Module: ActiveSupport::CoreExtensions::Numeric::Time

Included in:
Numeric
Defined in:
lib/active_support/core_ext/numeric/time.rb

Overview

Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years

Instance Method Summary collapse

Instance Method Details

#ago(time = ::Time.now) ⇒ Object Also known as: until

Reads best without arguments: 10.minutes.ago



42
43
44
# File 'lib/active_support/core_ext/numeric/time.rb', line 42

def ago(time = ::Time.now)
  time - self
end

#daysObject Also known as: day



16
17
18
# File 'lib/active_support/core_ext/numeric/time.rb', line 16

def days
  self * 24.hours
end

#fortnightsObject Also known as: fortnight



26
27
28
# File 'lib/active_support/core_ext/numeric/time.rb', line 26

def fortnights
  self * 2.weeks
end

#hoursObject Also known as: hour



11
12
13
# File 'lib/active_support/core_ext/numeric/time.rb', line 11

def hours
  self * 60.minutes
end

#minutesObject Also known as: minute



6
7
8
# File 'lib/active_support/core_ext/numeric/time.rb', line 6

def minutes
  self * 60
end

#monthsObject Also known as: month



31
32
33
# File 'lib/active_support/core_ext/numeric/time.rb', line 31

def months
  self * 30.days
end

#since(time = ::Time.now) ⇒ Object Also known as: from_now

Reads best with argument: 10.minutes.since(time)



50
51
52
# File 'lib/active_support/core_ext/numeric/time.rb', line 50

def since(time = ::Time.now)
  time + self
end

#weeksObject Also known as: week



21
22
23
# File 'lib/active_support/core_ext/numeric/time.rb', line 21

def weeks
  self * 7.days
end

#yearsObject Also known as: year



36
37
38
# File 'lib/active_support/core_ext/numeric/time.rb', line 36

def years
  self * 365.days
end