Permalink
Browse files

ActiveRecord::Base#instantiate_time_object only uses Time.zone when B…

…ase.time_zone_aware_attributes is true; leverages Time#time_with_datetime_fallback for readability

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8882 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 4e3ecec commit 2920bd22df21e9920b749ce3901522d494d551b7 @gbuesing gbuesing committed Feb 16, 2008
Showing with 19 additions and 2 deletions.
  1. +2 −0 activerecord/CHANGELOG
  2. +2 −2 activerecord/lib/active_record/base.rb
  3. +15 −0 activerecord/test/cases/base_test.rb
View
@@ -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]
@@ -2461,10 +2461,10 @@ def assign_multiparameter_attributes(pairs)
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
@@ -969,6 +969,21 @@ def test_multiparameter_attributes_on_time_with_time_zone_aware_attributes
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

0 comments on commit 2920bd2

Please sign in to comment.