https://github.com/richardvenneman/duration-formatter
:hourglass: Parse minutes into a readable format
https://github.com/richardvenneman/duration-formatter
days duration duration-format hours minutes time
Last synced: about 1 year ago
JSON representation
:hourglass: Parse minutes into a readable format
- Host: GitHub
- URL: https://github.com/richardvenneman/duration-formatter
- Owner: richardvenneman
- Created: 2015-07-02T14:51:49.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2016-10-04T15:07:29.000Z (over 9 years ago)
- Last Synced: 2025-02-24T19:40:18.223Z (over 1 year ago)
- Topics: days, duration, duration-format, hours, minutes, time
- Language: Ruby
- Homepage:
- Size: 285 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#duration-formatter
A simple gem to parse minutes into a readable format using [ruby-duration](https://github.com/peleteiro/ruby-duration).
[](http://rubygems.org/gems/duration-formatter)
[](https://travis-ci.org/richardvenneman/duration-formatter)
[](https://codeclimate.com/github/richardvenneman/duration-formatter)
[](https://codeclimate.com/github/richardvenneman/duration-formatter/coverage)
## Installation
This library is tested with the following Rubies: 2.2.5, 2.3.1.
Add it to your Gemfile with:
```ruby
gem 'duration-formatter'
```
Run the `bundle install` command in your terminal to install it.
## Usage
The gem exposes a class `FormattedDuration` which takes the passed minutes to determine the format. Calling `format` on the instance returns the formatted duration. Examples:
```ruby
# Full units
FormattedDuration.new(10080).format # => 1 week
FormattedDuration.new(1440).format # => 1 day
FormattedDuration.new(240).format # => 4 hours
FormattedDuration.new(20).format # => 20 minutes
# Composition
FormattedDuration.new(15840).format # => 1 week, 4 days
FormattedDuration.new(1450).format # => 1 day, 10 minutes
FormattedDuration.new(241).format # => 4 hours, 1 minute
```
### Constraints
You can also force a constraint upon the format.
```ruby
FormattedDuration.new(11520, :days).format # => 15 days (not "2 weeks, 1 day")
FormattedDuration.new(1440, :hours).format # => 24 hours
FormattedDuration.new(80, :minutes).format # => 80 minutes
```
## License
This library is released under the [MIT License](http://www.opensource.org/licenses/MIT).