提交 7316d029 编写于 作者: J Jay Pignata 提交者: Joshua Peek

Duplicating the options hash in Date#advance to prevent modification of the...

Duplicating the options hash in Date#advance to prevent modification of the original [#1133 state:resolved]
Signed-off-by: NJoshua Peek <josh@joshpeek.com>
上级 80989437
......@@ -82,6 +82,7 @@ def minus_with_duration(other) #:nodoc:
# Provides precise Date calculations for years, months, and days. The +options+ parameter takes a hash with
# any of these keys: <tt>:years</tt>, <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>.
def advance(options)
options = options.dup
d = self
d = d >> options.delete(:years) * 12 if options[:years]
d = d >> options.delete(:months) if options[:months]
......
......@@ -251,6 +251,12 @@ def test_current_returns_time_zone_today_when_zone_default_set
Time.zone_default = nil
end
def test_date_advance_should_not_change_passed_options_hash
options = { :years => 3, :months => 11, :days => 2 }
Date.new(2005,2,28).advance(options)
assert_equal({ :years => 3, :months => 11, :days => 2 }, options)
end
protected
def with_env_tz(new_tz = 'US/Eastern')
old_tz, ENV['TZ'] = ENV['TZ'], new_tz
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册