lib/tzinfo/time_or_datetime.rb in tzinfo-0.3.60 vs lib/tzinfo/time_or_datetime.rb in tzinfo-0.3.61
- old
+ new
@@ -176,10 +176,18 @@
# Compares this TimeOrDateTime with another Time, DateTime, integer
# timestamp or TimeOrDateTime. Returns -1, 0 or +1 depending whether the
# receiver is less than, equal to, or greater than timeOrDateTime.
#
# Milliseconds and smaller units are ignored in the comparison.
+ #
+ # Returns nil if the passed in timeOrDateTime is not comparable with
+ # TimeOrDateTime instances.
def <=>(timeOrDateTime)
+ return nil unless timeOrDateTime.is_a?(TimeOrDateTime) ||
+ timeOrDateTime.is_a?(Time) ||
+ timeOrDateTime.is_a?(DateTime) ||
+ timeOrDateTime.respond_to?(:to_i)
+
if timeOrDateTime.is_a?(TimeOrDateTime)
orig = timeOrDateTime.to_orig
if @orig.is_a?(DateTime) || orig.is_a?(DateTime)
# If either is a DateTime, assume it is there for a reason