Skip to content

Commit

Permalink
[rails#5559] Do not black out the system timezone DST jump hour if Ti…
Browse files Browse the repository at this point in the history
…me.zone 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 rails#5559.
  • Loading branch information
jarkko committed Mar 24, 2012
1 parent 014498e commit 03becb1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions activesupport/lib/active_support/values/time_zone.rb
Expand Up @@ -268,7 +268,12 @@ def parse(str, now=now)
date_parts = Date._parse(str)
return if date_parts.empty?
time = Time.parse(str, now) rescue DateTime.parse(str)

if date_parts[:offset].nil?
if date_parts[:hour] && time.hour != date_parts[:hour]
time = DateTime.parse(str)
end

ActiveSupport::TimeWithZone.new(nil, self, time)
else
time.in_time_zone(self)
Expand Down
18 changes: 18 additions & 0 deletions activesupport/test/time_zone_test.rb
Expand Up @@ -203,6 +203,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)
Expand Down

0 comments on commit 03becb1

Please sign in to comment.