aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/date
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2007-08-03 00:34:19 +0000
committerRick Olson <technoweenie@gmail.com>2007-08-03 00:34:19 +0000
commit4b6411008675dbbfb7da4dfb6ef73c5528c196d1 (patch)
tree7c9012bb5296ffb04c9576bbc29d61f5b8a4d0da /activesupport/lib/active_support/core_ext/date
parentbbbc45156bb2f903513116036619b78065f6d7e8 (diff)
downloadrails-4b6411008675dbbfb7da4dfb6ef73c5528c196d1.tar.gz
rails-4b6411008675dbbfb7da4dfb6ef73c5528c196d1.tar.bz2
rails-4b6411008675dbbfb7da4dfb6ef73c5528c196d1.zip
Fix Time#advance bug when trying to advance a year from leap day. Closes #8655 [gbuesing]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7262 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext/date')
-rw-r--r--activesupport/lib/active_support/core_ext/date/calculations.rb9
1 files changed, 5 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb
index 637c9ea02a..c28d0c876b 100644
--- a/activesupport/lib/active_support/core_ext/date/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/date/calculations.rb
@@ -68,9 +68,10 @@ module ActiveSupport #:nodoc:
# Provides precise Date calculations for years, months, and days. The +options+ parameter takes a hash with
# any of these keys: :months, :days, :years.
def advance(options)
- d = ::Date.new(year + (options.delete(:years) || 0), month, day)
- d = d >> options.delete(:months) if options[:months]
- d = d + options.delete(:days) if options[:days]
+ d = self
+ d = d >> options.delete(:years) * 12 if options[:years]
+ d = d >> options.delete(:months) if options[:months]
+ d = d + options.delete(:days) if options[:days]
d
end
@@ -78,7 +79,7 @@ module ActiveSupport #:nodoc:
#
# Examples:
#
- # Date.new(2007, 5, 12).change(:day => 1) # => Date.new(2007, 5, 12)
+ # Date.new(2007, 5, 12).change(:day => 1) # => Date.new(2007, 5, 1)
# Date.new(2007, 5, 12).change(:year => 2005, :month => 1) # => Date.new(2005, 1, 12)
def change(options)
::Date.new(