aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-06-07 09:38:15 -0600
committerSean Griffin <sean@thoughtbot.com>2014-06-07 09:38:15 -0600
commit3b22df2350dd671436ca5b1e4de4af3df9a8cca2 (patch)
tree8808ad0d2c04b0ded40b60a04c9562be84bd720f /activerecord/lib
parent2f5fab8d5af6dfe59e73fcf3d8d9902715b4284b (diff)
downloadrails-3b22df2350dd671436ca5b1e4de4af3df9a8cca2.tar.gz
rails-3b22df2350dd671436ca5b1e4de4af3df9a8cca2.tar.bz2
rails-3b22df2350dd671436ca5b1e4de4af3df9a8cca2.zip
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
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
index 44a679a550..c1c3987cf5 100644
--- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
+++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
@@ -10,7 +10,17 @@ module ActiveRecord
def 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