This project is archived and is in readonly mode.
Time + Duration misbehaves on DST boundary
-
Levin Alexander
ActiveSupport::TimeWithTimezone behaves as expected:
>> Time.local(2009,3,29,0,0,0).in_time_zone("CET") + 24.hours => Mon, 30 Mar 2009 01:00:00 CEST +02:00 # correct -
Levin Alexander
There are unit tests in time_ext_test.rb that call for the incorrect behavior:
def test_daylight_savings_time_crossings_forward_start with_env_tz 'US/Eastern' do # st: US: 2005 April 2nd 7:27pm assert_equal Time.local(2005,4,3,19,27,0), Time.local(2005,4,2,19,27,0).since(86400), 'st+1.day=>dt' assert_equal Time.local(2005,4,4,19,27,0), Time.local(2005,4,3,19,27,0).since(86400), 'dt+1.day=>dt' endIs Time#since really supposed to behave this way?
-
Geoff Buesing
- State changed from new to open
- Milestone cleared.
I agree, this is wonky behavior. Reason it exists at all is because, in the days before Rails had a proper Duration class (i.e., 2006), this was a way to fake a duration of 1 day and have it cross a DST boundary correctly.
Now that we have Duration, it's not needed, it's confusing, and needs to go. Adding 24.hours should always advance the time exactly 24 hours, and adding 1.day should advance to the same time on the next day, which will be 23-25 hours later, depending upon if a DST boundary was crossed.
A patch for this would be welcome.
-
Michael Curtis
- Tag changed from active_support, duration, timezone to active_support, duration, patch, timezone
This should take care of it. I've updated the unit tests in time_ext_test.rb that were enforcing the incorrect behavior, and added a couple tests to duration_test.rb that test this specific case.
This is my first patch to rails.. if I did anything wrong please let me know!
-
Manfred Stienstra
Michael, can you remove the commented lines? Also, the f variable doesn't seem necessary.
-
Pratik
- Assigned user set to Geoff Buesing
-
Geoff Buesing
Also, no longer a need to go through Numeric#since -- i.e. seconds.since(self) -- we should now be able to call Time#+ directly, i.e. self + seconds.
Time#since effectively becomes "plus with datetime fallback".
-
Michael Curtis
- Assigned user cleared.
Here's a new patch, reduced to one commit and no longer going through Numeric#since.
-
Michael Curtis
- Assigned user set to Geoff Buesing
-
Geoff Buesing
Revised patch looks good. I'll pull this in after 2.3 final is pushed. Thanks!
-
Repository
- State changed from open to resolved
(from [5a8b481f717470b952ac7eb890f260ea98428153]) Time.local instances: Adding 24.hours across the DST boundary adds 24 hours instead of one day [#2066 Time + Duration misbehaves on DST boundary state:resolved] http://github.com/rails/rails/co...
