mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Time.zone.parse: compatibility with far future date with time zone offset in string. Eliminate creation of additional TimeWithZone instance to determine utc offset.
This commit is contained in:
parent
328fada610
commit
fb9bf16e96
2 changed files with 13 additions and 3 deletions
|
@ -214,10 +214,11 @@ class TimeZone
|
|||
# Time.zone.parse('22:30:00') # => Fri, 31 Dec 1999 22:30:00 HST -10:00
|
||||
def parse(str, now=now)
|
||||
time = Time.parse(str, now) rescue DateTime.parse(str)
|
||||
unless time.is_a?(DateTime) || Date._parse(str)[:offset].nil?
|
||||
time += time.in_time_zone(self).utc_offset - time.utc_offset
|
||||
if Date._parse(str)[:offset].nil?
|
||||
ActiveSupport::TimeWithZone.new(nil, self, time)
|
||||
else
|
||||
time.in_time_zone(self)
|
||||
end
|
||||
ActiveSupport::TimeWithZone.new(nil, self, time)
|
||||
end
|
||||
|
||||
# Returns an ActiveSupport::TimeWithZone instance representing the current time
|
||||
|
|
|
@ -189,6 +189,15 @@ class TimeZoneTest < Test::Unit::TestCase
|
|||
assert_equal zone, twz.time_zone
|
||||
end
|
||||
end
|
||||
|
||||
def test_parse_far_future_date_with_time_zone_offset_in_string
|
||||
silence_warnings do # silence warnings raised by tzinfo gem
|
||||
zone = TimeZone['Eastern Time (US & Canada)']
|
||||
twz = zone.parse('2050-12-31 19:00:00 -10:00') # i.e., 2050-01-01 05:00:00 UTC
|
||||
assert_equal [0,0,0,1,1,2051], twz.to_a[0,6]
|
||||
assert_equal zone, twz.time_zone
|
||||
end
|
||||
end
|
||||
|
||||
uses_mocha 'TestParseWithIncompleteDate' do
|
||||
def test_parse_with_incomplete_date
|
||||
|
|
Loading…
Reference in a new issue