Skip to content

toreta/time_second

Repository files navigation

TimeSecond

Gem Version Build Status Maintainability Test Coverage

Make it easy to handle numeric value as seconds.

Installation

Add this line to your application's Gemfile:

gem 'time_second'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install time_second

Usage

# New from Integer
t = TimeSecond.new(2 * 60 * 60 + 1 * 60 + 39) # 2:01:39
t.hour   #=> 2
t.minute #=> 1
t.second #=> 39
t.hms    #=> '02:01:39'
t.hm     #=> '02:01'

# New from String
t = TimeSecond.parse('02:01:39')
t.to_i #=> 7299

# Support basic arithmetic operations
t = TimeSecond.new(7)
t + 3   #=> 10
t - 3   #=> 4
t * 3   #=> 21
t / 3   #=> 2
t / 3.0 #=> 2.3333333333333335
t % 3   #=> 1

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/toreta/time_second.

License

The gem is available as open source under the terms of the MIT License.