aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-04-01 00:31:53 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-04-01 00:31:53 -0300
commite3e28e4dab69c6707e123b9185d07ae1aaed46ea (patch)
tree839921aa804d0ab2087a38fe0ba47615ade46cbc /activesupport
parentbaa176e3f043dbea4e64dbc25dfa1b7ee02a9831 (diff)
parent97698606de78cef4bd2202ed04ce98d3a5f2d629 (diff)
downloadrails-e3e28e4dab69c6707e123b9185d07ae1aaed46ea.tar.gz
rails-e3e28e4dab69c6707e123b9185d07ae1aaed46ea.tar.bz2
rails-e3e28e4dab69c6707e123b9185d07ae1aaed46ea.zip
Merge pull request #19604 from aaronjensen/speed-up-time-coercion
Only coerce time when comparing if necessary
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/time/calculations.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb
index 6f1b653639..1ce68ea7c7 100644
--- a/activesupport/lib/active_support/core_ext/time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/time/calculations.rb
@@ -246,8 +246,10 @@ class Time
# Layers additional behavior on Time#<=> so that DateTime and ActiveSupport::TimeWithZone instances
# can be chronologically compared with a Time
def compare_with_coercion(other)
- # we're avoiding Time#to_datetime cause it's expensive
- if other.is_a?(Time)
+ # 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