utc_offset returns nil for unknown zones

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
Santiago Pastorino 2010-04-15 01:10:04 -03:00 committed by Jeremy Kemper
parent e79193f852
commit a0cc94b32e
2 changed files with 10 additions and 3 deletions

View File

@ -1,4 +1,5 @@
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/object/try'
# The TimeZone class serves as a wrapper around TZInfo::Timezone instances. It allows us to do the following:
#
@ -205,8 +206,8 @@ module ActiveSupport
if @utc_offset
@utc_offset
else
@current_period ||= tzinfo.current_period
@current_period.utc_offset
@current_period ||= tzinfo.try(:current_period)
@current_period.try(:utc_offset)
end
end

View File

@ -274,9 +274,15 @@ class TimeZoneTest < Test::Unit::TestCase
assert_raise(ArgumentError) { ActiveSupport::TimeZone[false] }
end
def test_unknown_zone_shouldnt_have_tzinfo
def test_unknown_zone_shouldnt_have_tzinfo_nor_utc_offset
zone = ActiveSupport::TimeZone.create("bogus")
assert_nil zone.tzinfo
assert_nil zone.utc_offset
end
def test_unknown_zone_with_utc_offset
zone = ActiveSupport::TimeZone.create("bogus", -21_600)
assert_equal -21_600, zone.utc_offset
end
def test_new