aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2013-06-03 16:42:41 +0200
committerDavid Heinemeier Hansson <david@loudthinking.com>2013-06-03 16:47:48 +0200
commita6fe33d8a3c09f3a70ee2a79f96ed5b2c9580d4f (patch)
treeea4a9dcced4302e0808ae46190d15ae11b06b600 /activesupport/lib
parentbb3d9a6f6c74dc1591639b779bf4272b272f93df (diff)
downloadrails-a6fe33d8a3c09f3a70ee2a79f96ed5b2c9580d4f.tar.gz
rails-a6fe33d8a3c09f3a70ee2a79f96ed5b2c9580d4f.tar.bz2
rails-a6fe33d8a3c09f3a70ee2a79f96ed5b2c9580d4f.zip
Allow Date to be compared with Time (like it was possible to compare Time with Date)
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/date/calculations.rb11
1 files changed, 11 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 106a65610c..c7e8b6ae25 100644
--- a/activesupport/lib/active_support/core_ext/date/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/date/calculations.rb
@@ -119,4 +119,15 @@ class Date
options.fetch(:day, day)
)
end
+
+ # Allow Dates to be compared with times. The Date will have its time set to 00:00:00 for the comparison.
+ def compare_with_coercion(other)
+ if other.is_a?(Time)
+ self.to_time <=> other
+ else
+ compare_without_coercion(other)
+ end
+ end
+ alias_method :compare_without_coercion, :<=>
+ alias_method :<=>, :compare_with_coercion
end