aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-05-15 08:24:25 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2012-05-15 08:24:25 -0700
commit1c3e5bee3d426666da9bbab84f1939c5f58b5640 (patch)
treeb7327f61bf17bd157b1e0b4cd53ad95d78b8f232
parente3cc49cff779564615c7e9275113cbf907cf5494 (diff)
parent03becb13099c439f6aea5058546bc8b0b19b8db8 (diff)
downloadrails-1c3e5bee3d426666da9bbab84f1939c5f58b5640.tar.gz
rails-1c3e5bee3d426666da9bbab84f1939c5f58b5640.tar.bz2
rails-1c3e5bee3d426666da9bbab84f1939c5f58b5640.zip
Merge pull request #5571 from jarkko/5559-fix-dst-jump-bug-on-master
[#5559] Do not black out the system timezone DST jump hour if Time.zone ...
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb5
-rw-r--r--activesupport/test/time_zone_test.rb18
2 files changed, 23 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index 0059898ebf..28bc06f103 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -271,7 +271,12 @@ module ActiveSupport
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)
diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb
index d14d01dc30..b9434489bb 100644
--- a/activesupport/test/time_zone_test.rb
+++ b/activesupport/test/time_zone_test.rb
@@ -203,6 +203,24 @@ class TimeZoneTest < ActiveSupport::TestCase
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)