aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorYasyf Mohamedali <yasyfm@gmail.com>2015-03-03 15:16:47 -0500
committerYasyf Mohamedali <yasyfm@gmail.com>2015-03-03 15:16:47 -0500
commit2cc2fa3633edd96773023c6b09d07c7b9d9b841d (patch)
tree214036adbdae276598736e7af29bfed3603caa46 /activesupport
parentb0edabf3be07f841781bc0b1743c401e666d2952 (diff)
downloadrails-2cc2fa3633edd96773023c6b09d07c7b9d9b841d.tar.gz
rails-2cc2fa3633edd96773023c6b09d07c7b9d9b841d.tar.bz2
rails-2cc2fa3633edd96773023c6b09d07c7b9d9b841d.zip
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.
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG.md10
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb8
-rw-r--r--activesupport/test/core_ext/time_with_zone_test.rb7
3 files changed, 24 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index 43fb87f203..f5fa70494a 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,3 +1,13 @@
+* 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.
+
+ Fixes #15209.
+
+ *Yasyf Mohamedali*
+
* Added `#without` on `Enumerable` and `Array` to return a copy of an
enumerable without the specified elements.
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)
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb
index 92c233d567..0f5522b712 100644
--- a/activesupport/test/core_ext/time_with_zone_test.rb
+++ b/activesupport/test/core_ext/time_with_zone_test.rb
@@ -867,6 +867,13 @@ class TimeWithZoneMethodsForTimeAndDateTimeTest < ActiveSupport::TestCase
end
end
+ def test_in_time_zone_with_dst
+ travel_to(Time.utc(2014, 5, 20, 4, 59, 59))
+ time = Time.now.in_time_zone(-4)
+ assert_equal (-4*3600), time.time_zone.utc_total_offset
+ travel_back
+ end
+
def test_in_time_zone_with_invalid_argument
assert_raise(ArgumentError) { @t.in_time_zone("No such timezone exists") }
assert_raise(ArgumentError) { @dt.in_time_zone("No such timezone exists") }