Duration

Duration is a simple class that provides ways of easily manipulating durations (timespans) and formatting them as well.

  require 'duration'
  => true
  d = Duration.new(60 * 60 * 24 * 10 + 120 + 30)
  => #<Duration: 1 week, 3 days, 2 minutes and 30 seconds>
  d.to_s
  => "1 week, 3 days, 2 minutes and 30 seconds"
  [d.weeks, d.days]
  => [1, 3]
  d.days = 7; d
  => #<Duration: 2 weeks, 2 minutes and 30 seconds>
  d.strftime('%w w, %d d, %h h, %m m, %s s')
  => "2 w, 0 d, 0 h, 2 m, 30 s"

Author

Notes

Copying

Copyright (c) 2006 Matthew Harris <shugotenshi at gmail.com>