aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorAgis- <corestudiosinc@gmail.com>2014-09-01 15:54:29 +0300
committerAgis- <corestudiosinc@gmail.com>2014-09-04 22:21:38 +0300
commit57b2c371f03982813f6dc2e7f07467b4fca3a6ce (patch)
tree47e244ea91e21fedd889d7a934d381200635e3f6 /activesupport
parent703a2e8da1d3a68b3902d9024c6f0d1cd32435aa (diff)
downloadrails-57b2c371f03982813f6dc2e7f07467b4fca3a6ce.tar.gz
rails-57b2c371f03982813f6dc2e7f07467b4fca3a6ce.tar.bz2
rails-57b2c371f03982813f6dc2e7f07467b4fca3a6ce.zip
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.
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG.md5
-rw-r--r--activesupport/lib/active_support/core_ext/time/calculations.rb1
-rw-r--r--activesupport/test/core_ext/time_ext_test.rb1
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