Skip to content

Commit

Permalink
Merge pull request #20398 from nkondratyev/fix-time-change
Browse files Browse the repository at this point in the history
Fix a range of values for parameters of the Time#change
  • Loading branch information
rafaelfranca committed Jun 1, 2015
1 parent e63d312 commit 87cbdd7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions activesupport/CHANGELOG.md
@@ -1,3 +1,7 @@
* Fix a range of values for parameters of the Time#change

*Nikolay Kondratyev*

* Add some missing `require 'active_support/deprecation'`

*Akira Matsuda*
Expand Down
Expand Up @@ -94,7 +94,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
raise ArgumentError, 'argument out of range' if new_usec >= 1000000
::Time.new(new_year, new_month, new_day, new_hour, new_min, new_sec + (new_usec.to_r / 1000000), utc_offset)
end
end
Expand Down
4 changes: 4 additions & 0 deletions activesupport/test/core_ext/time_ext_test.rb
Expand Up @@ -149,6 +149,9 @@ def test_end_of_day
assert_equal Time.local(2006,3,19,23,59,59,Rational(999999999, 1000)), Time.local(2006,3,19,10,10,10).end_of_day, 'ends DST'
assert_equal Time.local(2006,10,1,23,59,59,Rational(999999999, 1000)), Time.local(2006,10,1,10,10,10).end_of_day, 'start DST'
end
with_env_tz 'Asia/Yekaterinburg' do
assert_equal Time.local(2015, 2, 8, 23, 59, 59, Rational(999999999, 1000)), Time.new(2015, 2, 8, 8, 0, 0, '+05:00').end_of_day
end
end

def test_end_of_hour
Expand Down Expand Up @@ -389,6 +392,7 @@ def test_change
assert_equal Time.local(2005,1,2,11,22,33, 8), Time.local(2005,1,2,11,22,33,44).change(:usec => 8)
assert_equal Time.local(2005,1,2,11,22,33, 8), Time.local(2005,1,2,11,22,33,2).change(:nsec => 8000)
assert_raise(ArgumentError) { Time.local(2005,1,2,11,22,33, 8).change(:usec => 1, :nsec => 1) }
assert_nothing_raised(ArgumentError) { Time.new(2015, 5, 9, 10, 00, 00, '+03:00').change(nsec: 999999999) }
end

def test_utc_change
Expand Down

0 comments on commit 87cbdd7

Please sign in to comment.