Created
April 8, 2015 12:36
-
-
Save fcheung/632cb0e63ad314c34521 to your computer and use it in GitHub Desktop.
backport of https://github.com/rails/rails/pull/19604
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if Rails::VERSION::MAJOR > 4 | |
raise "This patch is obsolete and should be removed" | |
end | |
class Time | |
def compare_with_coercion(other) | |
# we're avoiding Time#to_datetime and Time#to_time because they're expensive | |
if other.class == Time | |
compare_without_coercion(other) | |
elsif other.is_a?(Time) | |
compare_without_coercion(other.to_time) | |
else | |
to_datetime <=> other | |
end | |
end | |
alias_method :<=>, :compare_with_coercion | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment