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 16
16:     def +(other)
17:       if Duration === other
18:         Duration.new(value + other.value, @parts + other.parts)
19:       else
20:         Duration.new(value + other, @parts + [[:seconds, other]])
21:       end
22:     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 26
26:     def -(other)
27:       self + (-other)
28:     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 40
40:     def ==(other)
41:       if Duration === other
42:         other.value == value
43:       else
44:         other == value
45:       end
46:     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 61
61:     def ago(time = ::Time.current)
62:       sum(-1, time)
63:     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 54
54:     def since(time = ::Time.current)
55:       sum(1, time)
56:     end
until(time = ::Time.current)

Alias for ago