Module: ActiveSupport::CoreExtensions::Numeric::Time
- Included in:
- Numeric
- Defined in:
- lib/action_controller/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
-
#ago(time = ::Time.now) ⇒ Object
(also: #until)
Reads best without arguments: 10.minutes.ago.
- #days ⇒ Object (also: #day)
- #fortnights ⇒ Object (also: #fortnight)
- #hours ⇒ Object (also: #hour)
- #minutes ⇒ Object (also: #minute)
- #months ⇒ Object (also: #month)
-
#since(time = ::Time.now) ⇒ Object
(also: #from_now)
Reads best with argument: 10.minutes.since(time).
- #weeks ⇒ Object (also: #week)
- #years ⇒ Object (also: #year)
Instance Method Details
#ago(time = ::Time.now) ⇒ Object Also known as: until
Reads best without arguments: 10.minutes.ago
42 43 44 |
# File 'lib/action_controller/support/core_ext/numeric/time.rb', line 42 def ago(time = ::Time.now) time - self end |
#days ⇒ Object Also known as: day
16 17 18 |
# File 'lib/action_controller/support/core_ext/numeric/time.rb', line 16 def days self * 24.hours end |
#fortnights ⇒ Object Also known as: fortnight
26 27 28 |
# File 'lib/action_controller/support/core_ext/numeric/time.rb', line 26 def fortnights self * 2.weeks end |
#hours ⇒ Object Also known as: hour
11 12 13 |
# File 'lib/action_controller/support/core_ext/numeric/time.rb', line 11 def hours self * 60.minutes end |
#minutes ⇒ Object Also known as: minute
6 7 8 |
# File 'lib/action_controller/support/core_ext/numeric/time.rb', line 6 def minutes self * 60 end |
#months ⇒ Object Also known as: month
31 32 33 |
# File 'lib/action_controller/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/action_controller/support/core_ext/numeric/time.rb', line 50 def since(time = ::Time.now) time + self end |
#weeks ⇒ Object Also known as: week
21 22 23 |
# File 'lib/action_controller/support/core_ext/numeric/time.rb', line 21 def weeks self * 7.days end |
#years ⇒ Object Also known as: year
36 37 38 |
# File 'lib/action_controller/support/core_ext/numeric/time.rb', line 36 def years self * 365.days end |