diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-06-07 14:44:12 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-06-07 14:44:12 +0200 |
commit | 23a751c2e15800c1b4aa96c10d1bfebc56fa30b9 (patch) | |
tree | 3aeb24a97d05dd1f0357e7e68d907428fdfe2c38 /activerecord/lib | |
parent | f84d081faf6812a947aebf3e67978f3d3bbb31f0 (diff) | |
parent | 1c181c295034a1b3ba8aefb9aede6552d8ff69e4 (diff) | |
download | rails-23a751c2e15800c1b4aa96c10d1bfebc56fa30b9.tar.gz rails-23a751c2e15800c1b4aa96c10d1bfebc56fa30b9.tar.bz2 rails-23a751c2e15800c1b4aa96c10d1bfebc56fa30b9.zip |
Merge pull request #15556 from sgrif/sg-time-zone-aware-arrays
Add array support when time zone aware attributes are enabled
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb | 14 |
1 files changed, 13 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 18778698e8..7db7d306a4 100644 --- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb +++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb @@ -32,7 +32,7 @@ module ActiveRecord if create_time_zone_conversion_attribute?(attr_name, columns_hash[attr_name]) method_body, line = <<-EOV, __LINE__ + 1 def #{attr_name}=(time) - time_with_zone = time.respond_to?(:in_time_zone) ? time.in_time_zone : nil + time_with_zone = convert_value_to_time_zone(time) previous_time = attribute_changed?("#{attr_name}") ? changed_attributes["#{attr_name}"] : read_attribute(:#{attr_name}) write_attribute(:#{attr_name}, time) #{attr_name}_will_change! if previous_time != time_with_zone @@ -52,6 +52,18 @@ module ActiveRecord (:datetime == column.type) end end + + private + + def convert_value_to_time_zone(value) + if value.is_a?(Array) + value.map { |v| convert_value_to_time_zone(v) } + elsif value.respond_to?(:in_time_zone) + value.in_time_zone + else + nil + end + end end end end |