aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorAndrey Novikov <envek@envek.name>2015-06-13 14:01:27 +0300
committerAndrey Novikov <envek@envek.name>2016-01-05 18:35:04 +0300
commit0a0ffb64d88949db29c235637eeadeea3eeaf292 (patch)
tree7d753486fa306053100af4a370a706dc7e354e84 /activemodel
parent3d90a6348d1541a2ecd00d959f9eec99ec78905a (diff)
downloadrails-0a0ffb64d88949db29c235637eeadeea3eeaf292.tar.gz
rails-0a0ffb64d88949db29c235637eeadeea3eeaf292.tar.bz2
rails-0a0ffb64d88949db29c235637eeadeea3eeaf292.zip
Take UTC offset into account when assigning string value to time attribute.
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/CHANGELOG.md5
-rw-r--r--activemodel/lib/active_model/type/time.rb2
-rw-r--r--activemodel/test/cases/types_test.rb3
3 files changed, 9 insertions, 1 deletions
diff --git a/activemodel/CHANGELOG.md b/activemodel/CHANGELOG.md
index e4769d2f40..463cca9350 100644
--- a/activemodel/CHANGELOG.md
+++ b/activemodel/CHANGELOG.md
@@ -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) ##
* Validate multiple contexts on `valid?` and `invalid?` at once.
diff --git a/activemodel/lib/active_model/type/time.rb b/activemodel/lib/active_model/type/time.rb
index fe09f63a87..34e09f0aba 100644
--- a/activemodel/lib/active_model/type/time.rb
+++ b/activemodel/lib/active_model/type/time.rb
@@ -38,7 +38,7 @@ module ActiveModel
fast_string_to_time(dummy_time_value) || begin
time_hash = ::Date._parse(dummy_time_value)
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
diff --git a/activemodel/test/cases/types_test.rb b/activemodel/test/cases/types_test.rb
index f937208580..558c56f157 100644
--- a/activemodel/test/cases/types_test.rb
+++ b/activemodel/test/cases/types_test.rb
@@ -64,6 +64,9 @@ module ActiveModel
time_string = Time.now.utc.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
def test_type_cast_datetime_and_timestamp