From 0599bfa2bc49c885fd4ec3ab7ecce37dc5c03ce5 Mon Sep 17 00:00:00 2001 From: pocke Date: Tue, 6 Jan 2015 21:56:39 +0900 Subject: DateTime#<=> return nil when compare to the invalid String as Time. before: p Time.now == 'a' # => false p Time.now <=> 'a' # => nil require 'active_support' require 'active_support/core_ext' p Time.now == 'a' # => false p Time.now <=> 'a' # => invalid date (ArgumentError) and on ruby 2.2, Time.now == 'a' warning. warning: Comparable#== will no more rescue exceptions of #<=> in the next release. warning: Return nil in #<=> if the comparison is inappropriate or avoid such comparison. after: - Error handling. - Quiet warnings. --- activesupport/lib/active_support/core_ext/date_time/calculations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib/active_support') 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 55ad384f4f..95617fb8c2 100644 --- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb @@ -168,7 +168,7 @@ class DateTime if other.kind_of?(Infinity) super elsif other.respond_to? :to_datetime - super other.to_datetime + super other.to_datetime rescue nil else nil end -- cgit v1.2.3