From a6fe33d8a3c09f3a70ee2a79f96ed5b2c9580d4f Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 3 Jun 2013 16:42:41 +0200 Subject: Allow Date to be compared with Time (like it was possible to compare Time with Date) --- .../lib/active_support/core_ext/date/calculations.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (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 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 -- cgit v1.2.3