diff options
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 4 | ||||
-rwxr-xr-x | activerecord/test/cases/base_test.rb | 15 |
3 files changed, 19 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 6231cc8bf8..d84445bd7d 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Base#instantiate_time_object only uses Time.zone when Base.time_zone_aware_attributes is true; leverages Time#time_with_datetime_fallback for readability [Geoff Buesing] + * Refactor ConnectionAdapters::Column.new_time: leverage DateTime failover behavior of Time#time_with_datetime_fallback [Geoff Buesing] * Improve associations performance by using symbol callbacks instead of string callbacks. #11108 [adymo] diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 481214c23c..a25d9789d7 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -2461,10 +2461,10 @@ module ActiveRecord #:nodoc: end def instantiate_time_object(name, values) - if Time.zone && !self.class.skip_time_zone_conversion_for_attributes.include?(name.to_sym) + if Time.zone && self.class.time_zone_aware_attributes && !self.class.skip_time_zone_conversion_for_attributes.include?(name.to_sym) Time.zone.local(*values) else - @@default_timezone == :utc ? Time.utc_time(*values) : Time.local_time(*values) + Time.time_with_datetime_fallback(@@default_timezone, *values) end end diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 9fde3130bd..4cba4a3ec6 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -969,6 +969,21 @@ class BasicsTest < ActiveRecord::TestCase end end + def test_multiparameter_attributes_on_time_with_time_zone_aware_attributes_false + ActiveRecord::Base.time_zone_aware_attributes = false + Time.zone = TimeZone[-28800] + attributes = { + "written_on(1i)" => "2004", "written_on(2i)" => "6", "written_on(3i)" => "24", + "written_on(4i)" => "16", "written_on(5i)" => "24", "written_on(6i)" => "00" + } + topic = Topic.find(1) + topic.attributes = attributes + assert_equal Time.local(2004, 6, 24, 16, 24, 0), topic.written_on + assert_equal false, topic.written_on.respond_to?(:time_zone) + ensure + Time.zone = nil + end + def test_multiparameter_attributes_on_time_with_skip_time_zone_conversion_for_attributes ActiveRecord::Base.time_zone_aware_attributes = true ActiveRecord::Base.default_timezone = :utc |