Skip to content

Commit

Permalink
Ruby 1.9 compat: TimeZone avoids localtime conversion. References #1689
Browse files Browse the repository at this point in the history
… [Chu Yeow]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8369 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Dec 10, 2007
1 parent d0b5f64 commit bcbcc02
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions activesupport/lib/active_support/values/time_zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,17 @@ def today

# 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

# Reinterprets the given time value as a time in the current time
# 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
Expand Down
2 changes: 1 addition & 1 deletion activesupport/test/time_zone_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_today
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

Expand Down

0 comments on commit bcbcc02

Please sign in to comment.