Provides accurate date and time measurements using Date#advance and Time#advance, respectively. It mainly supports the methods on Numeric, such as in this example:

  1.month.ago       # equivalent to Time.now.advance(:months => -1)
Methods
Attributes
[RW] parts
[RW] value
Public Instance methods
+(other)

Adds another Duration or a Numeric to this Duration. Numeric values are treated as seconds.

    # File activesupport/lib/active_support/duration.rb, line 18
18:     def +(other)
19:       if Duration === other
20:         Duration.new(value + other.value, @parts + other.parts)
21:       else
22:         Duration.new(value + other, @parts + [[:seconds, other]])
23:       end
24:     end
-(other)

Subtracts another Duration or a Numeric from this Duration. Numeric values are treated as seconds.

    # File activesupport/lib/active_support/duration.rb, line 28
28:     def -(other)
29:       self + (-other)
30:     end
==(other)

Returns true if other is also a Duration instance with the same value, or if other == value.

    # File activesupport/lib/active_support/duration.rb, line 42
42:     def ==(other)
43:       if Duration === other
44:         other.value == value
45:       else
46:         other == value
47:       end
48:     end
ago(time = ::Time.current)

Calculates a new Time or Date that is as far in the past as this Duration represents.

This method is also aliased as until
    # File activesupport/lib/active_support/duration.rb, line 63
63:     def ago(time = ::Time.current)
64:       sum(-1, time)
65:     end
from_now(time = ::Time.current)

Alias for since

since(time = ::Time.current)

Calculates a new Time or Date that is as far in the future as this Duration represents.

This method is also aliased as from_now
    # File activesupport/lib/active_support/duration.rb, line 56
56:     def since(time = ::Time.current)
57:       sum(1, time)
58:     end
until(time = ::Time.current)

Alias for ago