Class ActiveSupport::Duration
In: activesupport/lib/active_support/duration.rb
Parent: Builder::BlankSlate

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

+   -   ago   from_now   since   until  

Attributes

parts  [RW] 
value  [RW] 

Public Instance methods

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

[Source]

# File activesupport/lib/active_support/duration.rb, line 16
    def +(other)
      if Duration === other
        Duration.new(value + other.value, @parts + other.parts)
      else
        Duration.new(value + other, @parts + [[:seconds, other]])
      end
    end

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

[Source]

# File activesupport/lib/active_support/duration.rb, line 26
    def -(other)
      self + (-other)
    end

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

[Source]

# File activesupport/lib/active_support/duration.rb, line 51
    def ago(time = ::Time.now)
      sum(-1, time)
    end
from_now(time = ::Time.now)

Alias for since

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

[Source]

# File activesupport/lib/active_support/duration.rb, line 44
    def since(time = ::Time.now)
      sum(1, time)
    end
until(time = ::Time.now)

Alias for ago

[Validate]