From 420f877a62776b2c44f682ca69d5842c42255004 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 16 Jun 2010 16:48:07 -0700 Subject: [PATCH] ActiveSupport::TimeWithZone#period returns nil when it is created with a nil timezone. [#4881 state:resolved] --- activesupport/lib/active_support/time_with_zone.rb | 2 +- activesupport/test/time_zone_test.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletions(-) diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 710dce7..284931b 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -60,7 +60,7 @@ module ActiveSupport # Returns the underlying TZInfo::TimezonePeriod. def period - @period ||= time_zone.period_for_utc(@utc) + @period ||= time_zone && time_zone.period_for_utc(@utc) end # Returns the simultaneous time in Time.zone, or the specified zone. diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index 620623b..cde6c62 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -2,6 +2,11 @@ require 'abstract_unit' require 'active_support/time' class TimeZoneTest < Test::Unit::TestCase + def test_nil_zone + thing = Time.now.in_time_zone(nil) + assert_nil thing.period, 'period is nil' + end + def test_utc_to_local zone = ActiveSupport::TimeZone['Eastern Time (US & Canada)'] assert_equal Time.utc(1999, 12, 31, 19), zone.utc_to_local(Time.utc(2000, 1)) # standard offset -0500 -- 1.7.0.6