Regarding Date#change / #6910
May 30th, 2007
The new Date#change method (see previous post) in Active Support does not handle monthly length variations for you:
date = Date.new(2007, 05, 31)
date.to_s
=> "2007-05-31"
date = date.change(:month => 3)
date.to_s
=> "2007-03-31"
date = date.change(:month => 2)
ArgumentError: invalid date
Something to be aware of.
This is unlike Time#Change which will skip in to the next month:
datetime = Time.now
=> Thu May 31 15:06:31 -0400 2007
datetime.change(:month => 2)
=> Sat Mar 03 15:06:31 -0500 2007
Sorry, comments are closed for this article.