mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Ensure time zones don't change after round trip with array columns
The times would be equivalent, even if they were in different time zones. E.g. 12:00 UTC == 5:00 PDT
This commit is contained in:
parent
2f5fab8d5a
commit
3b22df2350
2 changed files with 13 additions and 1 deletions
|
@ -10,7 +10,17 @@ module ActiveRecord
|
||||||
|
|
||||||
def type_cast(value)
|
def type_cast(value)
|
||||||
value = @column.type_cast(value)
|
value = @column.type_cast(value)
|
||||||
value.acts_like?(:time) ? value.in_time_zone : value
|
convert_value_to_time_zone(value)
|
||||||
|
end
|
||||||
|
|
||||||
|
def convert_value_to_time_zone(value)
|
||||||
|
if value.is_a?(Array)
|
||||||
|
value.map { |v| convert_value_to_time_zone(v) }
|
||||||
|
elsif value.acts_like?(:time)
|
||||||
|
value.in_time_zone
|
||||||
|
else
|
||||||
|
value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -208,11 +208,13 @@ class PostgresqlArrayTest < ActiveRecord::TestCase
|
||||||
|
|
||||||
record = PgArray.new(datetimes: [time_string])
|
record = PgArray.new(datetimes: [time_string])
|
||||||
assert_equal [time], record.datetimes
|
assert_equal [time], record.datetimes
|
||||||
|
assert_equal ActiveSupport::TimeZone[tz], record.datetimes.first.time_zone
|
||||||
|
|
||||||
record.save!
|
record.save!
|
||||||
record.reload
|
record.reload
|
||||||
|
|
||||||
assert_equal [time], record.datetimes
|
assert_equal [time], record.datetimes
|
||||||
|
assert_equal ActiveSupport::TimeZone[tz], record.datetimes.first.time_zone
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue