Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

5559 fix dst jump bug #5560

Closed
wants to merge 1 commit into from

2 participants

@jarkko

The system timezone DST jump hour should not be blacked out by Time.zone.parse if current Time.zone does not do the jump at that time.

Tested on 1.8.7-p358, ree-1.8.7-2012.01 and ruby-1.9.3-p125.

Fixes #5559.

@jarkko jarkko [#5559] Do not black out the system timezone DST jump hour if Time.zo…
…ne differs from that.

The system timezone DST jump hour should not be blacked out by Time.zone.parse if current Time.zone does not do the jump at that time.

Fixes #5559.
bb4a1d6
@tenderlove
Owner

Can you send this pull request to master please? Then we'll backport to 3-2-stable.

@tenderlove tenderlove closed this
@jarkko

Yep. I also found a slight improvement to it, which I'll add to the request.

@tenderlove
Owner

Excellent. Thanks! :heart:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 23, 2012
  1. @jarkko

    [#5559] Do not black out the system timezone DST jump hour if Time.zo…

    jarkko authored
    …ne differs from that.
    
    The system timezone DST jump hour should not be blacked out by Time.zone.parse if current Time.zone does not do the jump at that time.
    
    Fixes #5559.
This page is out of date. Refresh to see the latest.
View
5 activesupport/lib/active_support/values/time_zone.rb
@@ -269,6 +269,11 @@ def parse(str, now=now)
date_parts = Date._parse(str)
return if date_parts.blank?
time = Time.parse(str, now) rescue DateTime.parse(str)
+
+ if date_parts[:hour] && time.hour != date_parts[:hour]
+ time = DateTime.parse(str)
+ end
+
if date_parts[:offset].nil?
ActiveSupport::TimeWithZone.new(nil, self, time)
else
View
20 activesupport/test/time_zone_test.rb
@@ -167,7 +167,7 @@ def test_parse_string_with_timezone
(-11..13).each do |timezone_offset|
zone = ActiveSupport::TimeZone[timezone_offset]
twz = zone.parse('1999-12-31 19:00:00')
- assert_equal twz, zone.parse(twz.to_s)
+ assert_equal twz.to_a, zone.parse(twz.to_s).to_a
end
end
@@ -198,6 +198,24 @@ def test_parse_with_incomplete_date
assert_equal Time.utc(1999,12,31,19), twz.time
end
+ def test_parse_should_not_black_out_system_timezone_dst_jump
+ zone = ActiveSupport::TimeZone['Pacific Time (US & Canada)']
+ zone.stubs(:now).returns(zone.now)
+ Time.stubs(:parse).with('2012-03-25 03:29', zone.now).
+ returns(Time.local(0,29,4,25,3,2012,nil,nil,true,"+03:00"))
+ twz = zone.parse('2012-03-25 03:29')
+ assert_equal [0, 29, 3, 25, 3, 2012], twz.to_a[0,6]
+ end
+
+ def test_parse_should_black_out_app_timezone_dst_jump
+ zone = ActiveSupport::TimeZone['Pacific Time (US & Canada)']
+ zone.stubs(:now).returns(zone.now)
+ Time.stubs(:parse).with('2012-03-11 02:29', zone.now).
+ returns(Time.local(0,29,2,11,3,2012,nil,nil,false,"+02:00"))
+ twz = zone.parse('2012-03-11 02:29')
+ assert_equal [0, 29, 3, 11, 3, 2012], twz.to_a[0,6]
+ end
+
def test_utc_offset_lazy_loaded_from_tzinfo_when_not_passed_in_to_initialize
tzinfo = TZInfo::Timezone.get('America/New_York')
zone = ActiveSupport::TimeZone.create(tzinfo.name, nil, tzinfo)
Something went wrong with that request. Please try again.