0.0
A long-lived project that still receives updates
This module provides functions for expressing durations
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 3.0
~> 13.0
 Project Readme

TimeDuration

Gem Version Test

Lengths of time, as opposed to clock times. Hours are never wrapped around a day, so fifty hours stays 50:00.

Installation

gem 'time-duration'

Usage

Parsing

TimeDuration.parse('1:10')   # => 1:10
TimeDuration.parse('1:70')   # => 2:10
TimeDuration.parse('-1:30')  # => -1:30

Building

TimeDuration::Duration.new                       # => 0:00
TimeDuration::Duration.new(minute: 10)           # => 0:10
TimeDuration::Duration.new(hour: 1, minute: 10)  # => 1:10

Shorthands for a single unit:

TimeDuration.hour(8)     # => 8:00
TimeDuration.minute(8)   # => 0:08
TimeDuration.second(90)  # => 0:01

Arithmetic

TimeDuration.parse('0:40') + TimeDuration.parse('0:30')   # => 1:10
TimeDuration.parse('0:40') - TimeDuration.parse('0:30')   # => 0:10
TimeDuration.parse('0:00') - TimeDuration.parse('0:01')   # => -0:01
TimeDuration.parse('50:00') + TimeDuration.parse('50:00') # => 100:00

Comparison

TimeDuration.parse('0:40') > TimeDuration.parse('0:30')   # => true
TimeDuration.parse('0:60') == TimeDuration.parse('1:00')  # => true

Durations that compare equal are also equal as hash keys:

[TimeDuration.parse('0:60'), TimeDuration.parse('1:00')].uniq.size  # => 1

Development

Run bin/setup to install dependencies, bundle exec rake to run the specs and RuboCop, and bin/console for an IRB session with the gem loaded.

Releasing

Run the Release workflow and choose a version bump. It tags the version, drafts the release notes, and publishes to RubyGems.org through trusted publishing.

Contributing

Bug reports and pull requests are welcome at https://github.com/d-mato/time_duration.

License

Released under the MIT License.