{"id":17826423,"url":"https://github.com/tylerrick/activesupport-duration-human_string","last_synced_at":"2025-03-18T23:31:01.511Z","repository":{"id":49144186,"uuid":"179127864","full_name":"TylerRick/activesupport-duration-human_string","owner":"TylerRick","description":"Convert Duration objects to human-friendly strings like '2h 30m 17s'","archived":false,"fork":false,"pushed_at":"2024-02-17T00:49:51.000Z","size":34,"stargazers_count":7,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-17T04:21:18.477Z","etag":null,"topics":["activesupport","duration","rails","ruby","serializer","string"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TylerRick.png","metadata":{"files":{"readme":"Readme.md","changelog":"Changelog.md","contributing":null,"funding":null,"license":"License","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-04-02T17:36:31.000Z","updated_at":"2025-02-26T21:18:21.000Z","dependencies_parsed_at":"2024-02-17T01:24:45.712Z","dependency_job_id":"686fe79b-8e00-4930-a261-06902a0d151c","html_url":"https://github.com/TylerRick/activesupport-duration-human_string","commit_stats":{"total_commits":5,"total_committers":2,"mean_commits":2.5,"dds":"0.19999999999999996","last_synced_commit":"559815af1390c8a05e44b594605188ed2ecff000"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Factivesupport-duration-human_string","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Factivesupport-duration-human_string/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Factivesupport-duration-human_string/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TylerRick%2Factivesupport-duration-human_string/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TylerRick","download_url":"https://codeload.github.com/TylerRick/activesupport-duration-human_string/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244325263,"owners_count":20435075,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activesupport","duration","rails","ruby","serializer","string"],"created_at":"2024-10-27T18:47:44.676Z","updated_at":"2025-03-18T23:31:01.208Z","avatar_url":"https://github.com/TylerRick.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ActiveSupport::Duration#human_string  [![Gem Version](https://badge.fury.io/rb/activesupport-duration-human_string.svg)](https://badge.fury.io/rb/activesupport-duration-human_string)\n\nConvert [ActiveSupport::Duration](https://api.rubyonrails.org/classes/ActiveSupport/Duration.html)\nobjects to human-friendly strings like `'2h 30m 17s'` or `'3y 6m 4d 12h 30m 5s'`.\n\n- Like [`distance_of_time_in_words`](https://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-distance_of_time_in_words)\n  helper but _exact_ rather than approximate\n  - `distance_of_time_in_words` is somewhat configurable but only gives an approximation (`'over 3\n    years'`), with no option to print the exact number of each units.\n- Like [`#inspect`](https://github.com/rails/rails/blob/b9ca94caea2ca6a6cc09abaffaad67b447134079/activesupport/lib/active_support/duration.rb#L372)\n  but more concise and configurable.\n  - `#inspect` is long (`'3 years, 6 months, 4 days, 12 hours, 30 minutes, and 5 seconds'`) and not\n    at all configurable.\n- Like [`#iso8601`](https://api.rubyonrails.org/classes/ActiveSupport/Duration.html#method-i-iso8601)\n  but more human readable rather than machine readable.\n  - `#iso8601` is concise and machine-readable, but not very human-readable (`'P3Y6M4DT12H30M5S'`)!\n- Unlike [`#to_s`](https://api.rubyonrails.org/classes/ActiveSupport/Duration.html#method-i-to_s),\n  which is very concise (`'110839937'`) but not at all human-readable for large durations\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'activesupport-duration-human_string'\n```\n\n## Usage\n\n```ruby\n    duration = 3500.seconds\n    duration.human_str                 # =\u003e  '58m 20s'\n    duration.human_str(delimiter: '')  # =\u003e  '58m20s'\n    duration.human_str(separator: ' ') # =\u003e  '58 m 20 s'\n    duration.human_str(delimiter: ', ', separator: ' ') # =\u003e  '58 m, 20 s'\n\n    duration = ActiveSupport::Duration.parse \"P3Y6M4DT12H30M5S\"\n    # =\u003e 3 years, 6 months, 4 days, 12 hours, 30 minutes, and 5 seconds\n\n    duration.human_str                  # =\u003e \"3y 6m 4d 12h 30m 5s\"\n    (duration - 4.days).human_str       # =\u003e \"3y 6m 12h 30m 5s\"\n    duration.human_str(delimiter: ', ') # =\u003e \"3y, 6m, 4d, 12h, 30m, 5s\"\n```\n\nAlso aliased as `human_string`, `to_human_s`.\n\n## See also\n\n- [activesupport-duration-change](https://github.com/TylerRick/activesupport-duration-change), which adds methods such as `#change`, `#truncate`, `#round` to `Duration`\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/TylerRick/activesupport-duration-human_string.\n\n## Not really related\n\n- https://github.com/josedonizetti/ruby-duration\n- https://github.com/janko/as-duration\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylerrick%2Factivesupport-duration-human_string","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftylerrick%2Factivesupport-duration-human_string","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftylerrick%2Factivesupport-duration-human_string/lists"}