From 2cc2fa3633edd96773023c6b09d07c7b9d9b841d Mon Sep 17 00:00:00 2001 From: Yasyf Mohamedali Date: Tue, 3 Mar 2015 15:16:47 -0500 Subject: Take DST into account when locating TimeZone from Numeric. When given a specific offset, use the first result found where the total current offset (including any periodic deviations such as DST) from UTC is equal. --- activesupport/lib/active_support/values/time_zone.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (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 da39f0d245..ab6a78052c 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -239,7 +239,7 @@ module ActiveSupport end when Numeric, ActiveSupport::Duration arg *= 3600 if arg.abs <= 13 - all.find { |z| z.utc_offset == arg.to_i } + all.find { |z| z.utc_total_offset == arg.to_i } else raise ArgumentError, "invalid argument to TimeZone[]: #{arg.inspect}" end @@ -285,6 +285,12 @@ module ActiveSupport end end + # Returns the offset of this time zone from UTC in seconds, + # taking DST into account. + def utc_total_offset + tzinfo.current_period.utc_total_offset if tzinfo + end + # Returns the offset of this time zone as a formatted string, of the # format "+HH:MM". def formatted_offset(colon=true, alternate_utc_string = nil) -- cgit v1.2.3