aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/time
diff options
context:
space:
mode:
authorMarc-Andre Lafortune <github@marc-andre.ca>2011-11-22 15:37:16 -0500
committerMarc-Andre Lafortune <github@marc-andre.ca>2011-11-22 15:37:16 -0500
commita4912078c7d345a347f023ef28c0986458bdebf5 (patch)
treea2a0a553fc815b2f6888f54b89ebd66ec82ab847 /activesupport/lib/active_support/core_ext/time
parentcb06727b6cb7310808f5b9ce1bf254055806ba80 (diff)
downloadrails-a4912078c7d345a347f023ef28c0986458bdebf5.tar.gz
rails-a4912078c7d345a347f023ef28c0986458bdebf5.tar.bz2
rails-a4912078c7d345a347f023ef28c0986458bdebf5.zip
Fix inconsistencies with Time{WithZone}#{hash,eql?}
Diffstat (limited to 'activesupport/lib/active_support/core_ext/time')
-rw-r--r--activesupport/lib/active_support/core_ext/time/calculations.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb
index 372dd69212..7a55086452 100644
--- a/activesupport/lib/active_support/core_ext/time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/time/calculations.rb
@@ -312,4 +312,14 @@ class Time
end
alias_method :compare_without_coercion, :<=>
alias_method :<=>, :compare_with_coercion
+
+ # Layers additional behavior on Time#eql? so that ActiveSupport::TimeWithZone instances
+ # can be eql? to an equivalent Time
+ def eql_with_coercion(other)
+ # if other is an ActiveSupport::TimeWithZone, coerce a Time instance from it so we can do eql? comparison
+ other = other.comparable_time if other.respond_to?(:comparable_time)
+ eql_without_coercion(other)
+ end
+ alias_method :eql_without_coercion, :eql?
+ alias_method :eql?, :eql_with_coercion
end