Skip to content

Commit

Permalink
Merge pull request #8927 from dkubb/issue-8178
Browse files Browse the repository at this point in the history
Fix DateTime comparison with DateTime::Infinity object
  • Loading branch information
rafaelfranca committed Jan 14, 2013
2 parents 7c62a75 + b1a501e commit 79a98d8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions activesupport/CHANGELOG.md
Expand Up @@ -19,6 +19,9 @@

*Daniele Sluijters*

* Fix DateTime comparison with DateTime::Infinity object.

*Dan Kubb*

## Rails 3.2.11 (Jan 8, 2012) ##

Expand Down
Expand Up @@ -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
6 changes: 6 additions & 0 deletions activesupport/test/core_ext/range_ext_test.rb
Expand Up @@ -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))
Expand Down

0 comments on commit 79a98d8

Please sign in to comment.