You can parse human time to seconds or convert seconds to human time.
Add nostradamus
in Gemfile and run bundle install
.
gem "nostradamus"
Or only execute gem install nostradamus
on terminal.
Nostradamus.parse("10:00") # => 36000
Nostradamus.parse("10:00:00") # => 36000
Nostradamus.humanize(36000, :short) # => "10:00"
Nostradamus.humanize(36000) # => "10:00:00"
time = Nostradamus.new("12:00") + 60
time.to_i # => 43260
time.to_s # => "12:01:00"
time.to_s(:short) # => "12:01"
time = Nostradamus.new("12:00") + Nostradamus.new(60)
time.to_i # => 43260
time.to_s # => "12:01:00"
time.to_s(:short) # => "12:01"
Nostradamus.new("12:00") == 43260
Nostradamus.new("00:01:00") == Nostradamus.new(60)
Nostradamus.new("12:00").to_time # => Returns a object: Time.new(CURRENT_YEAR, CURRENT_MONTH, CURRENT_DAY, 12, 0)
Nostradamus.new("12:00").to_time(:on => Date.new(2012, 5, 1)) # => Returns a object: Time.new(2012, 5, 1, 12, 0)
If you want to contribute, please:
- Fork the project.
- Make your feature addition or bug fix.
- Send me a pull request on Github.