Fix DateTime comparison with DateTime::Infinity object

Fixes #16406
上级 d25fe31c
* Fix DateTime comparison with DateTime::Infinity object.
*Rafael Mendonça França*
* Added Object#itself which returns the object itself. Useful when dealing with a chaining scenario, like Active Record scopes:
Event.public_send(state.presence_in([ :trashed, :drafted ]) || :itself).order(:created_at)
......
......@@ -161,7 +161,9 @@ def utc_offset
# Layers additional behavior on DateTime#<=> so that Time and
# ActiveSupport::TimeWithZone instances can be compared with a DateTime.
def <=>(other)
if other.respond_to? :to_datetime
if other.kind_of?(Infinity)
super
elsif other.respond_to? :to_datetime
super other.to_datetime
else
nil
......
......@@ -16,6 +16,7 @@ def test_to_s_from_times
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册