aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/core_ext/date/calculations.rb6
-rw-r--r--activesupport/test/core_ext/duration_test.rb6
3 files changed, 12 insertions, 2 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index f1e40389e9..7d42bf9e5c 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fix that Dates couldn't be subtracted from Dates after [5940]. [Sam Stephenson]
+
* Add Object#acts_like? and Time#acts_like_time? and Date#acts_like_date? to facilitate duck-typing. [Jamis Buck]
* Make 1.months and friends accurate by introducing a Duration class. #6835 [eventualbuddha]
diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb
index f81cd9187e..b104e5271a 100644
--- a/activesupport/lib/active_support/core_ext/date/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/date/calculations.rb
@@ -23,7 +23,11 @@ module ActiveSupport #:nodoc:
end
def minus_with_duration(other) #:nodoc:
- self.plus_with_duration(-other)
+ if ActiveSupport::Duration === other
+ plus_with_duration(-other)
+ else
+ minus_without_duration(other)
+ end
end
# Provides precise Date calculations for years, months, and days. The +options+ parameter takes a hash with
diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb
index 78fc999052..22950d8710 100644
--- a/activesupport/test/core_ext/duration_test.rb
+++ b/activesupport/test/core_ext/duration_test.rb
@@ -10,4 +10,8 @@ class DurationTest < Test::Unit::TestCase
assert_equal '7 days', 1.week.inspect
assert_equal '14 days', 1.fortnight.inspect
end
-end \ No newline at end of file
+
+ def test_minus_with_duration_does_not_break_subtraction_of_date_from_date
+ assert_nothing_raised { Date.today - Date.today }
+ end
+end