method
months_since
v1.2.6 -
Show latest stable
- Class:
ActiveSupport::CoreExtensions::Time::Calculations
months_since(months)public
No documentation available.
# File activesupport/lib/active_support/core_ext/time/calculations.rb, line 77
def months_since(months)
year, month, mday = self.year, self.month, self.mday
month += months
# in case months is negative
while month < 1
month += 12
year -= 1
end
# in case months is positive
while month > 12
month -= 12
year += 1
end
max = ::Time.days_in_month(month, year)
mday = max if mday > max
change(:year => year, :month => month, :mday => mday)
end