diff options
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/date/calculations.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb index fef49e1003..2612dca93a 100644 --- a/activesupport/lib/active_support/core_ext/date/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date/calculations.rb @@ -4,6 +4,24 @@ require 'active_support/core_ext/time/zones' require 'active_support/core_ext/object/acts_like' class Date + if RUBY_VERSION < '1.9' + undef :>> + + # Backported from 1.9. The one in 1.8 leads to incorrect next_month and + # friends for dates where the calendar reform is involved. It additionally + # prevents an infinite loop fixed in r27013. + def >>(n) + y, m = (year * 12 + (mon - 1) + n).divmod(12) + m, = (m + 1) .divmod(1) + d = mday + until jd2 = self.class.valid_civil?(y, m, d, start) + d -= 1 + raise ArgumentError, 'invalid date' unless d > 0 + end + self + (jd2 - jd) + end + end + class << self # Returns a new Date representing the date 1 day ago (i.e. yesterday's date). def yesterday |