Permalink
Browse files

Check `respond_to` before delegation due to: ruby/ruby@d781caa

  • Loading branch information...
tenderlove committed Jan 9, 2014
1 parent 2213cb8 commit 2ec916ba1ec560b054e5e32ebe8f94ea891816b8
@@ -158,7 +158,11 @@ 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
+ if other.respond_to? :to_datetime
+ super other.to_datetime
+ else
+ nil
+ end
end
end
@@ -232,6 +232,7 @@ def formatted_offset(colon=true, alternate_utc_string = nil)
# Compare this time zone to the parameter. The two are compared first on
# their offsets, and then by name.
def <=>(zone)
+ return unless zone.respond_to? :utc_offset
result = (utc_offset <=> zone.utc_offset)
result = (name <=> zone.name) if result == 0
result

0 comments on commit 2ec916b

Please sign in to comment.