0.01
No commit activity in last 3 years
No release in over 3 years
Time calculation
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 3.5.0

Runtime

>= 0.3.33
 Project Readme

The Nostradamus gem

You can parse human time to seconds or convert seconds to human time.

Install nostradamus gem

Add nostradamus in Gemfile and run bundle install.

gem "nostradamus"

Or only execute gem install nostradamus on terminal.

How to use

Human time to seconds:

Nostradamus.parse("10:00") # => 36000
Nostradamus.parse("10:00:00") # => 36000

Seconds to human time:

Nostradamus.humanize(36000, :short) # => "10:00"
Nostradamus.humanize(36000) # => "10:00:00"

Sum with seconds

time = Nostradamus.new("12:00") + 60
time.to_i # => 43260
time.to_s # => "12:01:00"
time.to_s(:short) # => "12:01"

Sum with another Nostradamus instance

time = Nostradamus.new("12:00") + Nostradamus.new(60)
time.to_i # => 43260
time.to_s # => "12:01:00"
time.to_s(:short) # => "12:01"

Compare times

Nostradamus.new("12:00") == 43260
Nostradamus.new("00:01:00") == Nostradamus.new(60)

Returning a Time object

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)

Contributing

If you want to contribute, please:

  • Fork the project.
  • Make your feature addition or bug fix.
  • Send me a pull request on Github.

Code Status

Build Status