jeremyevans/home_run — Issue #46: seconds round down unexpectedly when fractional days are added to DateTime
Author: chittoor
Created: 2012-03-01 03:26:12+00:00
State: open

Example:
tested on 1.8.7 p358

```ruby
>> dt = DateTime.parse("Wed Feb 29 20:00:05 -0500 2012")
=> Wed, 29 Feb 2012 20:00:05 -0500
>> ndt = dt + 35373468 / 86400.0
=> Sun, 14 Apr 2013 05:57:52 -0500
>> ndt.sec
=> 52
>> ndt.sec_fraction
=> 1.15740740509259e-05
>>
?> t = Time.parse("Wed Feb 29 20:00:05 -0500 2012")
=> Wed Feb 29 20:00:05 -0500 2012
>> nt = t + 35373468
=> Sun Apr 14 06:57:53 -0400 2013
>> nt.sec
=> 53
>> nt.usec
=> 0
>>
?> ndt.sec_fraction * 86400
=> 0.999999998
```

This is not a remote/edge case issue. It's quite easy to catch.
We have internally added a hack to the functions rhrdt__nanos_to_hms and rhrdt_sec_fraction to round the seconds up if it's close enough (100 ns).
Ugly but seems to work without accidentally rounding off on DateTime.now and others which generate fractional seconds.

Please note that the floating point arith involved is still pretty accurate at this range.