Monthly Archives: June 2009
Ruby Duration
[download id="1" format="1"]
Duration.new recieves a string describing a duration of time, and converts it into: seconds, and a standard readable format.
Or, you can pass Duration.new an integer representing seconds, and receive the same standard readable format.
Usage:
Passing a String
duration = Duration.new("2weeks 8 hr 30m")
duration.seconds # => 1240200
duration.readable # => "2 weeks, 8 hours [...]
Splash