aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2013-01-22 13:18:56 +0000
committerAndrew White <andyw@pixeltrix.co.uk>2013-01-22 14:16:59 +0000
commit5c4a186dd520de6f157efe2cf8c6e7e745acfb0e (patch)
tree8dc0cca0635001254e4a8c359e8bca8781e34e15 /activerecord/lib/active_record/attribute_methods
parent1cf73a6fed772ec6b02cd8c7e8d0e93cb2f17c57 (diff)
downloadrails-5c4a186dd520de6f157efe2cf8c6e7e745acfb0e.tar.gz
rails-5c4a186dd520de6f157efe2cf8c6e7e745acfb0e.tar.bz2
rails-5c4a186dd520de6f157efe2cf8c6e7e745acfb0e.zip
Revert "Round usec when writing timestamp attribute."
This reverts commit e9d2ad395ec2ef929d74752f3d71c80674044fbe. Closes #8460 Conflicts: activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb activerecord/test/cases/dirty_test.rb
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods')
-rw-r--r--activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb18
1 files changed, 5 insertions, 13 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 47a8b576c0..7701001da9 100644
--- a/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
+++ b/activerecord/lib/active_record/attribute_methods/time_zone_conversion.rb
@@ -39,14 +39,11 @@ module ActiveRecord
unless time.acts_like?(:time)
time = time.is_a?(String) ? Time.zone.parse(time) : time.to_time rescue time
end
- zoned_time = time && time.in_time_zone rescue nil
- rounded_time = round_usec(zoned_time)
- rounded_value = round_usec(read_attribute("#{attr_name}"))
- if (rounded_value != rounded_time) || (!rounded_value && original_time)
- write_attribute("#{attr_name}", original_time)
- #{attr_name}_will_change!
- @attributes_cache["#{attr_name}"] = zoned_time
- end
+ time = time.in_time_zone rescue nil if time
+ changed = read_attribute(:#{attr_name}) != time
+ write_attribute(:#{attr_name}, original_time)
+ #{attr_name}_will_change! if changed
+ @attributes_cache["#{attr_name}"] = time
end
EOV
generated_attribute_methods.module_eval(method_body, __FILE__, line)
@@ -62,11 +59,6 @@ module ActiveRecord
[:datetime, :timestamp].include?(column.type)
end
end
-
- private
- def round_usec(value)
- value.change(usec: 0) if value
- end
end
end
end