1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #20544 from Envek/fix_utc_offset_for_time_attributes

Take UTC offset into account when assigning string value to time attributes.
This commit is contained in:
Rafael França 2016-01-05 22:59:11 -02:00
commit 11e7c605a4
3 changed files with 9 additions and 1 deletions

View file

@ -1,3 +1,8 @@
* Take into account UTC offset when assigning string representation of
timestamp with offset specified to attribute of time type.
*Andrey Novikov*
## Rails 5.0.0.beta1 (December 18, 2015) ## ## Rails 5.0.0.beta1 (December 18, 2015) ##
* Validate multiple contexts on `valid?` and `invalid?` at once. * Validate multiple contexts on `valid?` and `invalid?` at once.

View file

@ -38,7 +38,7 @@ module ActiveModel
fast_string_to_time(dummy_time_value) || begin fast_string_to_time(dummy_time_value) || begin
time_hash = ::Date._parse(dummy_time_value) time_hash = ::Date._parse(dummy_time_value)
return if time_hash[:hour].nil? return if time_hash[:hour].nil?
new_time(*time_hash.values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction)) new_time(*time_hash.values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction, :offset))
end end
end end
end end

View file

@ -64,6 +64,9 @@ module ActiveModel
time_string = Time.now.utc.strftime("%T") time_string = Time.now.utc.strftime("%T")
assert_equal time_string, type.cast(time_string).strftime("%T") assert_equal time_string, type.cast(time_string).strftime("%T")
assert_equal ::Time.utc(2000, 1, 1, 16, 45, 54), type.cast('2015-06-13T19:45:54+03:00')
assert_equal ::Time.utc(1999, 12, 31, 21, 7, 8), type.cast('06:07:08+09:00')
end end
def test_type_cast_datetime_and_timestamp def test_type_cast_datetime_and_timestamp