From bcbcc0260b4f75e9da7f009dfc7e3e0233158274 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 10 Dec 2007 10:05:43 +0000 Subject: Ruby 1.9 compat: TimeZone avoids localtime conversion. References #1689 [Chu Yeow] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8369 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/lib/active_support/values/time_zone.rb | 7 ++++--- activesupport/test/time_zone_test.rb | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 71e8528ae1..cd4b84bdc7 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -45,7 +45,7 @@ class TimeZone # Adjust the given time to the time zone represented by +self+. def adjust(time) - time = time.to_time + time = time.to_time unless time.is_a?(::Time) time + utc_offset - time.utc_offset end @@ -53,8 +53,9 @@ class TimeZone # zone, and then adjusts it to return the corresponding time in the # local time zone. def unadjust(time) - time = Time.local(*time.to_time.to_a) - time - utc_offset + time.utc_offset + time = time.to_time unless time.is_a?(::Time) + time = time.localtime + time - utc_offset - time.utc_offset end # Compare this time zone to the parameter. The two are comapred first on diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index 080ccef8ac..bf41f14741 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -34,7 +34,7 @@ class TimeZoneTest < Test::Unit::TestCase end def test_adjust_negative - zone = TimeZone.create( "Test", -4200 ) + zone = TimeZone.create( "Test", -4200 ) # 4200s == 70 mins assert_equal Time.utc(2004,7,24,23,55,0), zone.adjust(Time.utc(2004,7,25,1,5,0)) end -- cgit v1.2.3