diff options
author | Andrew White <pixeltrix@users.noreply.github.com> | 2014-09-05 07:51:08 +0100 |
---|---|---|
committer | Andrew White <pixeltrix@users.noreply.github.com> | 2014-09-05 07:51:08 +0100 |
commit | c4fbe14cac259a0c503d1e027c67ad872afd3d70 (patch) | |
tree | 6263e6970d7808bf19ef03e4636afc59420c9bda | |
parent | 7d69eae78ab9fd5472dcc7ed43d83621e2f80339 (diff) | |
parent | 57b2c371f03982813f6dc2e7f07467b4fca3a6ce (diff) | |
download | rails-c4fbe14cac259a0c503d1e027c67ad872afd3d70.tar.gz rails-c4fbe14cac259a0c503d1e027c67ad872afd3d70.tar.bz2 rails-c4fbe14cac259a0c503d1e027c67ad872afd3d70.zip |
Merge pull request #16765 from Agis-/time-change-bug
Time#change throws exception with an out-of-range :usec
-rw-r--r-- | activesupport/CHANGELOG.md | 5 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 1 | ||||
-rw-r--r-- | activesupport/test/core_ext/time_ext_test.rb | 1 |
3 files changed, 7 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 62e16ed9bd..cae5ac6e17 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,8 @@ +* 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. diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 89cd7516cd..6a7bf7445a 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -87,6 +87,7 @@ class Time 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 diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index c8283cddc5..9a5bd19be2 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -405,6 +405,7 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase 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 |