utc_offset returns nil for unknown zones
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
parent
e79193f852
commit
a0cc94b32e
|
@ -1,4 +1,5 @@
|
||||||
require 'active_support/core_ext/object/blank'
|
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:
|
# 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
|
if @utc_offset
|
||||||
@utc_offset
|
@utc_offset
|
||||||
else
|
else
|
||||||
@current_period ||= tzinfo.current_period
|
@current_period ||= tzinfo.try(:current_period)
|
||||||
@current_period.utc_offset
|
@current_period.try(:utc_offset)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -274,9 +274,15 @@ class TimeZoneTest < Test::Unit::TestCase
|
||||||
assert_raise(ArgumentError) { ActiveSupport::TimeZone[false] }
|
assert_raise(ArgumentError) { ActiveSupport::TimeZone[false] }
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_unknown_zone_shouldnt_have_tzinfo
|
def test_unknown_zone_shouldnt_have_tzinfo_nor_utc_offset
|
||||||
zone = ActiveSupport::TimeZone.create("bogus")
|
zone = ActiveSupport::TimeZone.create("bogus")
|
||||||
assert_nil zone.tzinfo
|
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
|
end
|
||||||
|
|
||||||
def test_new
|
def test_new
|
||||||
|
|
Loading…
Reference in New Issue