From 4e68b159d5696ca58c015a790ef3ceacb90b27c1 Mon Sep 17 00:00:00 2001 From: bogdanvlviv Date: Sat, 31 Mar 2018 18:16:32 +0300 Subject: Move implementation of `before?` and `after?` to `DateAndTime::Calculations` This prevents duplication of code. Prevent duplication of tests by moving them to `DateAndTimeBehavior`. Related to #32185. --- activesupport/lib/active_support/core_ext/date/calculations.rb | 2 -- .../lib/active_support/core_ext/date_and_time/calculations.rb | 10 ++++++++++ .../lib/active_support/core_ext/date_time/calculations.rb | 2 -- activesupport/lib/active_support/core_ext/time/calculations.rb | 2 -- 4 files changed, 10 insertions(+), 6 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb index e7be5c1376..1cd7acb05d 100644 --- a/activesupport/lib/active_support/core_ext/date/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date/calculations.rb @@ -142,6 +142,4 @@ class Date end alias_method :compare_without_coercion, :<=> alias_method :<=>, :compare_with_coercion - alias_method :before?, :< - alias_method :after?, :> end diff --git a/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb index f6cb1a384c..de13f00e60 100644 --- a/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb @@ -60,6 +60,16 @@ module DateAndTime !WEEKEND_DAYS.include?(wday) end + # Returns true if the date/time before date_or_time. + def before?(date_or_time) + self < date_or_time + end + + # Returns true if the date/time after date_or_time. + def after?(date_or_time) + self > date_or_time + end + # Returns a new date/time the specified number of days ago. def days_ago(days) advance(days: -days) diff --git a/activesupport/lib/active_support/core_ext/date_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb index eace125883..e61b23f842 100644 --- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb @@ -208,6 +208,4 @@ class DateTime super end end - alias_method :before?, :< - alias_method :after?, :> end diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 0507f9e652..120768dec5 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -302,8 +302,6 @@ class Time end alias_method :compare_without_coercion, :<=> alias_method :<=>, :compare_with_coercion - alias_method :before?, :< - alias_method :after?, :> # Layers additional behavior on Time#eql? so that ActiveSupport::TimeWithZone instances # can be eql? to an equivalent Time -- cgit v1.2.3