diff options
author | Gordon Chan <developer.gordon+github@gmail.com> | 2014-05-30 20:29:30 +1200 |
---|---|---|
committer | Gordon Chan <developer.gordon+github@gmail.com> | 2014-05-30 20:41:39 +1200 |
commit | c69baffdf752e2255fe1efc80ce32017bb1896e7 (patch) | |
tree | acf37a7ea044c9513fbe9b12b2d5c1e8b9a437ca /activesupport/lib | |
parent | 6963e33829c11f7036b8c8015e2c5222a469c118 (diff) | |
download | rails-c69baffdf752e2255fe1efc80ce32017bb1896e7.tar.gz rails-c69baffdf752e2255fe1efc80ce32017bb1896e7.tar.bz2 rails-c69baffdf752e2255fe1efc80ce32017bb1896e7.zip |
Fixed `ActiveSupport::TimeWithZone#-` so precision is not unnecessarily lost
When working with objects with a nanosecond component, the `-` method may
unnecessarily cause loss of precision.
`ActiveSupport::TimeWithZone#-` should return the same result as if we were
using `Time#-`:
Time.now.end_of_day - Time.now.beginning_of_day #=> 86399.999999999
Before:
Time.zone.now.end_of_day.nsec #=> 999999999
Time.zone.now.end_of_day - Time.zone.now.beginning_of_day #=> 86400.0
After:
Time.zone.now.end_of_day - Time.zone.now.beginning_of_day
#=> 86399.999999999
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/time_with_zone.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index f2a2f3c3db..d6ffe37833 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -262,7 +262,7 @@ module ActiveSupport # If we're subtracting a Duration of variable length (i.e., years, months, days), move backwards from #time, # otherwise move backwards #utc, for accuracy when moving across DST boundaries if other.acts_like?(:time) - utc.to_f - other.to_f + to_time - other.to_time elsif duration_of_variable_length?(other) method_missing(:-, other) else |