Skip to content

Commit

Permalink
when the timezone is nil, a TimeWithZone object should not be constru…
Browse files Browse the repository at this point in the history
…cted. [#4881 state:resolved]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information
tenderlove authored and jeremy committed Jun 17, 2010
1 parent 84d387b commit 5ae7a9d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions activesupport/lib/active_support/core_ext/date_time/zones.rb
Expand Up @@ -12,6 +12,8 @@ class DateTime
#
# DateTime.new(2000).in_time_zone('Alaska') # => Fri, 31 Dec 1999 15:00:00 AKST -09:00
def in_time_zone(zone = ::Time.zone)
return self unless zone

ActiveSupport::TimeWithZone.new(utc? ? self : getutc, ::Time.__send__(:get_zone, zone))
end
end
2 changes: 2 additions & 0 deletions activesupport/lib/active_support/core_ext/time/zones.rb
Expand Up @@ -73,6 +73,8 @@ def get_zone(time_zone)
#
# Time.utc(2000).in_time_zone('Alaska') # => Fri, 31 Dec 1999 15:00:00 AKST -09:00
def in_time_zone(zone = ::Time.zone)
return self unless zone

ActiveSupport::TimeWithZone.new(utc? ? self : getutc, ::Time.__send__(:get_zone, zone))
end
end
7 changes: 7 additions & 0 deletions activesupport/test/core_ext/time_with_zone_test.rb
Expand Up @@ -737,6 +737,13 @@ def test_in_time_zone
end
end

def test_nil_time_zone
Time.use_zone nil do
assert !@t.in_time_zone.respond_to?(:period), 'no period method'
assert !@dt.in_time_zone.respond_to?(:period), 'no period method'
end
end

def test_in_time_zone_with_argument
Time.use_zone 'Eastern Time (US & Canada)' do # Time.zone will not affect #in_time_zone(zone)
assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @t.in_time_zone('Alaska').inspect
Expand Down

0 comments on commit 5ae7a9d

Please sign in to comment.