aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorGeoff Buesing <gbuesing@gmail.com>2008-02-16 20:47:01 +0000
committerGeoff Buesing <gbuesing@gmail.com>2008-02-16 20:47:01 +0000
commit2920bd22df21e9920b749ce3901522d494d551b7 (patch)
tree3f338da2d6cf33e72ecd16acb5ff0f73874f9c0b /activerecord
parent4e3ecec9c76c612facd995031fb1c2a499d5d4c4 (diff)
downloadrails-2920bd22df21e9920b749ce3901522d494d551b7.tar.gz
rails-2920bd22df21e9920b749ce3901522d494d551b7.tar.bz2
rails-2920bd22df21e9920b749ce3901522d494d551b7.zip
ActiveRecord::Base#instantiate_time_object only uses Time.zone when Base.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
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/base.rb4
-rwxr-xr-xactiverecord/test/cases/base_test.rb15
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