aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/date_time/calculations.rb
diff options
context:
space:
mode:
authorAndrew White <andrew.white@unboxedconsulting.com>2016-04-03 23:43:53 +0100
committerAndrew White <andrew.white@unboxedconsulting.com>2016-04-03 23:47:46 +0100
commit08073125a5bd4cae0f2e02723e7743a389d496cd (patch)
treee290932b105597ea893565b1f62420cf6b0c4dd8 /activesupport/lib/active_support/core_ext/date_time/calculations.rb
parentae2f193c0379453f73ae08a3df541d2cb0ae00e2 (diff)
downloadrails-08073125a5bd4cae0f2e02723e7743a389d496cd.tar.gz
rails-08073125a5bd4cae0f2e02723e7743a389d496cd.tar.bz2
rails-08073125a5bd4cae0f2e02723e7743a389d496cd.zip
Call super instead of returning nil for DateTime#<=>
The native DateTime#<=> implementation can be used to compare instances with numeric values being considered as astronomical julian day numbers so we should call that instead of returning nil. Fixes #24228.
Diffstat (limited to 'activesupport/lib/active_support/core_ext/date_time/calculations.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/date_time/calculations.rb7
1 files changed, 2 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/core_ext/date_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb
index 95617fb8c2..ac46f5ffe8 100644
--- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb
@@ -165,13 +165,10 @@ class DateTime
# Layers additional behavior on DateTime#<=> so that Time and
# ActiveSupport::TimeWithZone instances can be compared with a DateTime.
def <=>(other)
- if other.kind_of?(Infinity)
- super
- elsif other.respond_to? :to_datetime
+ if other.respond_to? :to_datetime
super other.to_datetime rescue nil
else
- nil
+ super
end
end
-
end