提交 57b2c371 编写于 作者: A Agis-

Time#change throws exception with an out-of-range :usec

https://github.com/rails/rails/commit/98b46bf5e201307cae56ee14bf41363a539779c5
did not properly handled out-of-range `:usec`s.

Passing a `:usec` that's out of range now throws an `ArgumentError` as it
should.

Fixes #16759.
上级 703a2e8d
* Make Time#change throw an exception if the :usec option is out of range and
the time has an offset other than UTC or local.
*Agis Anastasopoulos*
* `Method` objects now report themselves as not `duplicable?`. This allows
hashes and arrays containing `Method` objects to be `deep_dup`ed.
......
......@@ -87,6 +87,7 @@ def change(options)
elsif zone
::Time.local(new_year, new_month, new_day, new_hour, new_min, new_sec, new_usec)
else
raise ArgumentError, 'argument out of range' if new_usec > 999999
::Time.new(new_year, new_month, new_day, new_hour, new_min, new_sec + (new_usec.to_r / 1000000), utc_offset)
end
end
......
......@@ -405,6 +405,7 @@ def test_offset_change
assert_equal Time.new(2005,2,22,16,0,0,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(:hour => 16)
assert_equal Time.new(2005,2,22,16,45,0,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(:hour => 16, :min => 45)
assert_equal Time.new(2005,2,22,15,45,0,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(:min => 45)
assert_raise(ArgumentError) { Time.new(2005, 2, 22, 15, 15, 45, "-08:00").change(:usec => 1000000) }
end
def test_advance
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册