Skip to content
Browse files

Fix ActiveSupport::TimeWithZone#localtime method with DateTime

[#5344 state:committed]

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
1 parent 7611a09 commit 387a1a6365d6452961fce6ac61a8ca6db99a1ed1 @alvarobp alvarobp committed with spastorino Sep 11, 2010
View
2 activesupport/lib/active_support/time_with_zone.rb
@@ -72,7 +72,7 @@ def in_time_zone(new_zone = ::Time.zone)
# Returns a <tt>Time.local()</tt> instance of the simultaneous time in your system's <tt>ENV['TZ']</tt> zone
def localtime
- utc.getlocal
+ utc.is_a?(DateTime) ? utc.to_time.getlocal : utc.getlocal
end
alias_method :getlocal, :localtime
View
11 activesupport/test/core_ext/time_with_zone_test.rb
@@ -36,6 +36,10 @@ def test_in_time_zone_with_new_zone_equal_to_old_zone_does_not_create_new_object
assert_equal @twz.object_id, @twz.in_time_zone(ActiveSupport::TimeZone['Eastern Time (US & Canada)']).object_id
end
+ def test_localtime
+ assert_equal @twz.localtime, @twz.utc.getlocal
+ end
+
def test_utc?
assert_equal false, @twz.utc?
assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000), ActiveSupport::TimeZone['UTC']).utc?
@@ -763,6 +767,13 @@ def test_in_time_zone_with_time_local_instance
end
end
+ def test_localtime
+ Time.zone_default = ActiveSupport::TimeZone['Eastern Time (US & Canada)']
+ assert_equal @dt.in_time_zone.localtime, @dt.in_time_zone.utc.to_time.getlocal
+ ensure
+ Time.zone_default = nil
+ end
+
def test_use_zone
Time.zone = 'Alaska'
Time.use_zone 'Hawaii' do

0 comments on commit 387a1a6

Please sign in to comment.
Something went wrong with that request. Please try again.