Skip to content
Make it easy to handle integer as seconds
Ruby
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
test
.gitignore
.rubocop.yml
.rubocop_todo.yml
.travis.yml
CHANGELOG.md
Gemfile
Gemfile.lock
LICENSE.txt
README.md
Rakefile
time_second.gemspec

README.md

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.

You can’t perform that action at this time.