aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/base.rb3
-rwxr-xr-xactiverecord/test/cases/base_test.rb11
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