Browse files

Fix TimeWithZone#to_time to return self

A previous commit (7872cc9) changed it to return utc to simplify the Time#<==>
override. An alternative method acheives the same result while
preserving original behaviour.
  • Loading branch information...
adzap committed Aug 7, 2011
1 parent ed10107 commit 0784a7c4ce9b603427fd02ab47b530952ff3d021
@@ -379,9 +379,10 @@ def minus_with_coercion(other)
# Layers additional behavior on Time#<=> so that DateTime and ActiveSupport::TimeWithZone instances
# can be chronologically compared with a Time
def compare_with_coercion(other)
+ other = other.comparable_time if other.respond_to?(:comparable_time)
# we're avoiding Time#to_datetime cause it's expensive
if other.is_a?(Time)
- compare_without_coercion(other.to_time)
+ compare_without_coercion(other)
to_datetime <=> other
@@ -279,7 +279,7 @@ def to_i
# A TimeWithZone acts like a Time, so just return +self+.
def to_time
- utc
+ self
def to_datetime
@@ -319,7 +319,7 @@ def test_to_i_with_wrapped_datetime
def test_to_time
- assert_equal @twz, @twz.to_time
+ assert @twz.equal?(@twz.to_time)
def test_to_date

0 comments on commit 0784a7c

Please sign in to comment.