rails/rails — pull request #15421 by gchan (2014-05-30 08:52:59+00:00)
Title: 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.

The current implementation converts both objects to a `Float` before preforming float subtraction. This pull request changes this so we convert to native Ruby `Time` objects and call `Time#-` to maximize 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