diff options
Diffstat (limited to 'activesupport/lib/active_support/core_ext/time/calculations.rb')
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 11 |
1 files changed, 11 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 eb342084a8..7fbfca5b2a 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -13,6 +13,9 @@ module ActiveSupport #:nodoc: alias_method :minus_without_duration, :- alias_method :-, :minus_with_duration + alias_method :minus_without_coercion, :- + alias_method :-, :minus_with_coercion + alias_method :compare_without_coercion, :<=> alias_method :<=>, :compare_with_coercion end @@ -218,6 +221,14 @@ module ActiveSupport #:nodoc: end end + # Time#- can also be used to determine the number of seconds between two Time instances. + # We're layering on additional behavior so that ActiveSupport::TimeWithZone instances + # are coerced into values that Time#- will recognize + def minus_with_coercion(other) + other = other.comparable_time if other.respond_to?(:comparable_time) + minus_without_coercion(other) + end + # Layers additional behavior on Time#<=> so that DateTime and ActiveSupport::TimeWithZone instances # can be chronologically compared with a Time def compare_with_coercion(other) |