From ba910d76509158d531c637c4ab777beb8b20e53d Mon Sep 17 00:00:00 2001 From: Andrew White Date: Wed, 13 Mar 2013 04:45:47 +0000 Subject: Fix `ActiveSupport::TimeZone.parse` when time is a local DST jump The previous implementation `ActiveSupport::TimeZone.parse` used `Time.parse` which applies the system time DST rules to the parsed time. Instead we now use `Time.utc` and manually apply the offset. Backport tests from: 005d910624bbfa724b638426a000c8074d4201a2 c89b6c4cdce7ee55ed3665c099d914222fe0344a 03becb13099c439f6aea5058546bc8b0b19b8db8 Fixes #9678. --- .../lib/active_support/values/time_zone.rb | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index c7d8fc2e17..f935180036 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -268,13 +268,23 @@ module ActiveSupport # Time.zone.now # => Fri, 31 Dec 1999 14:00:00 HST -10:00 # Time.zone.parse('22:30:00') # => Fri, 31 Dec 1999 22:30:00 HST -10:00 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[:offset].nil? - ActiveSupport::TimeWithZone.new(nil, self, time) + parts = Date._parse(str, false) + return if parts.empty? + + time = Time.utc( + parts.fetch(:year, now.year), + parts.fetch(:mon, now.month), + parts.fetch(:mday, now.day), + parts.fetch(:hour, 0), + parts.fetch(:min, 0), + parts.fetch(:sec, 0), + parts.fetch(:sec_fraction, 0) * 1000000 + ) + + if parts[:offset] + TimeWithZone.new(time - parts[:offset], self) else - time.in_time_zone(self) + TimeWithZone.new(nil, self, time) end end -- cgit v1.2.3