aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2018-03-26 18:33:03 -0400
committerGitHub <noreply@github.com>2018-03-26 18:33:03 -0400
commit9a9ef9639ea4837d8585eb4528a6aa21ade19cb8 (patch)
tree7907b5415ff5279cd8f3858f11ae864de97eaa4e /activesupport/lib
parent93e6b5c27bfdfd75714233772bf2b19045c7d1a9 (diff)
parent20fa0d92c36681f6cffc715e08c299ff942352f4 (diff)
downloadrails-9a9ef9639ea4837d8585eb4528a6aa21ade19cb8.tar.gz
rails-9a9ef9639ea4837d8585eb4528a6aa21ade19cb8.tar.bz2
rails-9a9ef9639ea4837d8585eb4528a6aa21ade19cb8.zip
Merge pull request #32185 from nholden/human_readable_date_time_comparisons
Add `before?` and `after?` methods to date and time classes
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/date/calculations.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/date_time/calculations.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/time/calculations.rb2
-rw-r--r--activesupport/lib/active_support/time_with_zone.rb2
4 files changed, 8 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb
index 1cd7acb05d..e7be5c1376 100644
--- a/activesupport/lib/active_support/core_ext/date/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/date/calculations.rb
@@ -142,4 +142,6 @@ 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_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb
index e61b23f842..eace125883 100644
--- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb
@@ -208,4 +208,6 @@ 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 120768dec5..0507f9e652 100644
--- a/activesupport/lib/active_support/core_ext/time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/time/calculations.rb
@@ -302,6 +302,8 @@ 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
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
index 20650ce714..7e71318404 100644
--- a/activesupport/lib/active_support/time_with_zone.rb
+++ b/activesupport/lib/active_support/time_with_zone.rb
@@ -225,6 +225,8 @@ module ActiveSupport
def <=>(other)
utc <=> other
end
+ alias_method :before?, :<
+ alias_method :after?, :>
# Returns true if the current object's time is within the specified
# +min+ and +max+ time.