Permalink
Browse files

Fixed that Time.local(2005,12).months_since(1) would raise "ArgumentE…

…rror: argument out of range" #1311 [jhahn@niveon.com]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1308 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
dhh committed May 19, 2005
1 parent aa20834 commit e84deb71d2e8a2855aba01bf88a710c8ae5ab1dc
@@ -48,7 +48,8 @@ def months_ago(months)
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
@@ -37,7 +37,9 @@ def test_months_ago
def test_months_since
assert_equal Time.local(2005,7,5,10), Time.local(2005,6,5,10,0,0).months_since(1)
+ assert_equal Time.local(2006,1,5,10), Time.local(2005,12,5,10,0,0).months_since(1)
assert_equal Time.local(2005,12,5,10), Time.local(2005,6,5,10,0,0).months_since(6)
+ assert_equal Time.local(2006,6,5,10), Time.local(2005,12,5,10,0,0).months_since(6)
assert_equal Time.local(2006,1,5,10), Time.local(2005,6,5,10,0,0).months_since(7)
assert_equal Time.local(2006,6,5,10), Time.local(2005,6,5,10,0,0).months_since(12)
assert_equal Time.local(2007,6,5,10), Time.local(2005,6,5,10,0,0).months_since(24)

0 comments on commit e84deb7

Please sign in to comment.