diff options
author | Geoff Buesing <gbuesing@gmail.com> | 2008-02-10 22:46:31 +0000 |
---|---|---|
committer | Geoff Buesing <gbuesing@gmail.com> | 2008-02-10 22:46:31 +0000 |
commit | c9402b2277b18e65064720cc9ebf272a321de1ff (patch) | |
tree | b65600cf4405d49522e54f0fac688614db8da13c | |
parent | 6608a3ef37a8f998958b867a1be186d33edbc151 (diff) | |
download | rails-c9402b2277b18e65064720cc9ebf272a321de1ff.tar.gz rails-c9402b2277b18e65064720cc9ebf272a321de1ff.tar.bz2 rails-c9402b2277b18e65064720cc9ebf272a321de1ff.zip |
Multiparameter attributes for time columns fail over to DateTime when out of range of Time
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8855 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 3 | ||||
-rwxr-xr-x | activerecord/test/cases/base_test.rb | 11 |
3 files changed, 14 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index b45d6e3373..591433b48c 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Multiparameter attributes for time columns fail over to DateTime when out of range of Time [Geoff Buesing] + * Base#instantiate_time_object uses Time.zone.local() [Geoff Buesing] * Add timezone-aware attribute readers and writers. #10982 [Geoff Buesing] diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index f273c04a94..642a7e2b96 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -2472,12 +2472,11 @@ module ActiveRecord #:nodoc: ) end - # Includes an ugly hack for Time.local instead of Time.new because the latter is reserved by Time itself. def instantiate_time_object(name, values) if Time.zone && !self.class.skip_time_zone_conversion_for_attributes.include?(name.to_sym) Time.zone.local(*values) else - @@default_timezone == :utc ? Time.utc(*values) : Time.local(*values) + @@default_timezone == :utc ? Time.utc_time(*values) : Time.local_time(*values) end end diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 93a40267fc..e98a756870 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -923,6 +923,17 @@ class BasicsTest < ActiveRecord::TestCase topic.attributes = attributes assert_equal Time.local(2004, 6, 24, 16, 24, 0), topic.written_on end + + def test_multiparameter_attributes_on_time_with_old_date + attributes = { + "written_on(1i)" => "1850", "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 + # testing against to_s(:db) representation because either a Time or a DateTime might be returned, depending on platform + assert_equal "1850-06-24 16:24:00", topic.written_on.to_s(:db) + end def test_multiparameter_attributes_on_time_with_utc ActiveRecord::Base.default_timezone = :utc |