No commit activity in last 3 years
No release in over 3 years
A simple gem to parse minutes into a readable format using ruby-duration.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

#duration-formatter

A simple gem to parse minutes into a readable format using ruby-duration.

Gem Build Status Code Climate Test Coverage

Installation

This library is tested with the following Rubies: 2.2.5, 2.3.1.

Add it to your Gemfile with:

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:

# 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.

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.