Enables the use of time calculations and declarations, like 45.minutes + 2.hours + 4.years.
If you need precise date calculations that doesn’t just treat months as 30 days, then have a look at Time#advance.
Some of these methods are approximations, Ruby’s core Date and Time should be used for precision date and time arithmetic
- A
- D
- F
- H
- M
- S
- U
- W
- Y
Reads best without arguments: 10.minutes.ago
Source: show
# File rails/activesupport/lib/active_support/core_ext/numeric/time.rb, line 55 def ago(time = ::Time.now) time - self end
Source: show
# File rails/activesupport/lib/active_support/core_ext/numeric/time.rb, line 29 def days self * 24.hours end
Source: show
# File rails/activesupport/lib/active_support/core_ext/numeric/time.rb, line 39 def fortnights self * 2.weeks end
Source: show
# File rails/activesupport/lib/active_support/core_ext/numeric/time.rb, line 24 def hours self * 60.minutes end
Source: show
# File rails/activesupport/lib/active_support/core_ext/numeric/time.rb, line 19 def minutes self * 60 end
Source: show
# File rails/activesupport/lib/active_support/core_ext/numeric/time.rb, line 44 def months self * 30.days end
Source: show
# File rails/activesupport/lib/active_support/core_ext/numeric/time.rb, line 14 def seconds self end
Reads best with argument: 10.minutes.since(time)
Source: show
# File rails/activesupport/lib/active_support/core_ext/numeric/time.rb, line 63 def since(time = ::Time.now) time + self end