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
- ago
- day
- days
- fortnight
- fortnights
- from_now
- hour
- hours
- minute
- minutes
- month
- months
- second
- seconds
- since
- until
- week
- weeks
- year
- years
Reads best without arguments: 10.minutes.ago
[ show source ]
# File vendor/rails/activesupport/lib/active_support/core_ext/numeric/time.rb, line 55
55: def ago(time = ::Time.now)
56: time - self
57: end
Alias for days
[ show source ]
# File vendor/rails/activesupport/lib/active_support/core_ext/numeric/time.rb, line 29
29: def days
30: self * 24.hours
31: end
Alias for fortnights
[ show source ]
# File vendor/rails/activesupport/lib/active_support/core_ext/numeric/time.rb, line 39
39: def fortnights
40: self * 2.weeks
41: end
Alias for since
Alias for hours
[ show source ]
# File vendor/rails/activesupport/lib/active_support/core_ext/numeric/time.rb, line 24
24: def hours
25: self * 60.minutes
26: end
Alias for minutes
[ show source ]
# File vendor/rails/activesupport/lib/active_support/core_ext/numeric/time.rb, line 19
19: def minutes
20: self * 60
21: end
Alias for months
[ show source ]
# File vendor/rails/activesupport/lib/active_support/core_ext/numeric/time.rb, line 44
44: def months
45: self * 30.days
46: end
Alias for seconds
[ show source ]
# File vendor/rails/activesupport/lib/active_support/core_ext/numeric/time.rb, line 14
14: def seconds
15: self
16: end
Reads best with argument: 10.minutes.since(time)
[ show source ]
# File vendor/rails/activesupport/lib/active_support/core_ext/numeric/time.rb, line 63
63: def since(time = ::Time.now)
64: time + self
65: end
Alias for ago
Alias for weeks
[ show source ]
# File vendor/rails/activesupport/lib/active_support/core_ext/numeric/time.rb, line 34
34: def weeks
35: self * 7.days
36: end
Alias for years
[ show source ]
# File vendor/rails/activesupport/lib/active_support/core_ext/numeric/time.rb, line 49
49: def years
50: (self * 365.25.days).to_i
51: end