1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Support datetime values in AR::Type::DateTime#type_cast_for_database

This commit is contained in:
brainopia 2015-01-03 02:03:47 +03:00
parent 78dab2a856
commit e8d6ba218a
2 changed files with 13 additions and 1 deletions

View file

@ -11,7 +11,11 @@ module ActiveRecord
zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
if value.acts_like?(:time)
value.send(zone_conversion_method)
if value.respond_to?(zone_conversion_method)
value.send(zone_conversion_method)
else
value
end
else
super
end

View file

@ -50,4 +50,12 @@ class DateTimeTest < ActiveRecord::TestCase
topic.bonus_time = ''
assert_nil topic.bonus_time
end
def test_assign_in_local_timezone
now = DateTime.now
with_timezone_config default: :local do
task = Task.new starting: now
assert now, task.starting
end
end
end