Steps to reproduce:
1. Create a time object with fractional microseconds:
t = Time.new(2012, 10, 17, 23, 59, 59, 999999.9)
2. Add 1 to time, and convert to an integer. Result is off by one:
(t + 1).to_i - t.to_i #=> 2
Impact:
ActiveSupport's extensions to the Time class utilize fractional microseconds in the #end_of_day method. When Time objects created with this method are converted back to DateTime objects (via the TZInfo library), the result is a DateTime object with a value for the start of the next day. This can lead to issues with generating intervals for a full day (i.e. resulting in 97 15-minute intervals per day instead of 96). For example:
Time.now.in_time_zone('America/New_York').end_of_day.to_datetime
#=> Thu, 18 Oct 2012 00:00:00 -0400
Regression:
This functioned as expected in JRuby 1.6.7.2:
> RUBY_ENGINE
=> "jruby"
> RUBY_VERSION
=> "1.9.2"
> JRUBY_VERSION
=> "1.6.7.2"
> t = Time.new(2012, 10, 17, 23, 59, 59, 999999.9)
=> 2012-10-17 23:59:59 +0300
> (t + 1).to_i - t.to_i
=> 1
|