Revert "Take DST into account when locating TimeZone from Numeric."

Reverting this as it's not the implementation that we would like it to be.
This is being used inside of ActiveSUpport::TimeZone[] and it's unaware
of the context in which to find the timezone period so the timezone found
changes depending on whether DST is in effect for the current period.
This means that `'2001-01-01'.in_time_zone(-9)` changes from winter/summer
even though it's the same date that we're trying to convert.

Since finding timezones by numeric offsets is a bit hit and miss we should
introduce a new API for finding them which supplies the date context in
which we want to search and we should probably also deprecate the finding
of timezones via the [] method, though this needs further discussion.

This reverts commit 2cc2fa3633.
This commit is contained in:
Andrew White 2015-03-09 13:48:55 +00:00
parent 309ac642cb
commit 34b27701ee
3 changed files with 1 additions and 24 deletions

View File

@ -1,13 +1,3 @@
* 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.

View File

@ -239,7 +239,7 @@ module ActiveSupport
end
when Numeric, ActiveSupport::Duration
arg *= 3600 if arg.abs <= 13
all.find { |z| z.utc_total_offset == arg.to_i }
all.find { |z| z.utc_offset == arg.to_i }
else
raise ArgumentError, "invalid argument to TimeZone[]: #{arg.inspect}"
end
@ -285,12 +285,6 @@ 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)

View File

@ -867,13 +867,6 @@ 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") }