From e84deb71d2e8a2855aba01bf88a710c8ae5ab1dc Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 19 May 2005 16:36:04 +0000 Subject: Fixed that Time.local(2005,12).months_since(1) would raise "ArgumentError: argument out of range" #1311 [jhahn@niveon.com] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1308 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/lib/active_support/core_ext/time/calculations.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/core_ext/time/calculations.rb') diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index acc84017ab..f238ca168a 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -48,7 +48,8 @@ module ActiveSupport #:nodoc: def months_since(months) if months + self.month > 12 - change(:year => self.year + 1, :month => 1).months_since(months - (self.month == 1 ? 12 : (self.month + 1))) + old_time = self + change(:year => self.year + 1, :month => 1).months_since(months + old_time.month - 12 - 1) else change(:year => self.year, :month => self.month + months) end -- cgit v1.2.3