Permalink
Browse files

Merge pull request #8927 from dkubb/issue-8178

Fix DateTime comparison with DateTime::Infinity object
  • Loading branch information...
2 parents 7c62a75 + b1a501e commit 79a98d82daf3614f7e17b1436005cf3b10e83557 @rafaelfranca rafaelfranca committed Jan 14, 2013
@@ -19,6 +19,9 @@
*Daniele Sluijters*
+* Fix DateTime comparison with DateTime::Infinity object.
+
+ *Dan Kubb*
## Rails 3.2.11 (Jan 8, 2012) ##
@@ -138,6 +138,6 @@ def utc_offset
# Layers additional behavior on DateTime#<=> so that Time and ActiveSupport::TimeWithZone instances can be compared with a DateTime
def <=>(other)
- super other.to_datetime
+ super other.kind_of?(Infinity) ? other : other.to_datetime
end
end
@@ -12,6 +12,12 @@ def test_to_s_from_times
date_range = Time.utc(2005, 12, 10, 15, 30)..Time.utc(2005, 12, 10, 17, 30)
assert_equal "BETWEEN '2005-12-10 15:30:00' AND '2005-12-10 17:30:00'", date_range.to_s(:db)
end
+
+ def test_date_range
+ assert_instance_of Range, DateTime.new..DateTime.new
+ assert_instance_of Range, DateTime::Infinity.new..DateTime::Infinity.new
+ assert_instance_of Range, DateTime.new..DateTime::Infinity.new
+ end
def test_overlaps_last_inclusive
assert((1..5).overlaps?(5..10))

0 comments on commit 79a98d8

Please sign in to comment.