diff options
author | Yehuda Katz <wycats@gmail.com> | 2011-11-22 13:01:37 -0800 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2011-11-22 13:01:37 -0800 |
commit | a93ee92da2b9ba83e3a3fe0b8d4dd5cac2790f15 (patch) | |
tree | 46a33467eca7a163117ed439c65b02e96248060e /activesupport/lib/active_support/core_ext | |
parent | 9b7be78820c5510b2f841dc2197ed3a32ad8dd19 (diff) | |
parent | a4912078c7d345a347f023ef28c0986458bdebf5 (diff) | |
download | rails-a93ee92da2b9ba83e3a3fe0b8d4dd5cac2790f15.tar.gz rails-a93ee92da2b9ba83e3a3fe0b8d4dd5cac2790f15.tar.bz2 rails-a93ee92da2b9ba83e3a3fe0b8d4dd5cac2790f15.zip |
Merge pull request #3725 from marcandre/twz_eql
Fix inconsistencies with Time{WithZone}#{hash,eql?}
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 10 |
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 43cd103481..1e15529569 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 |