From 33f222b9e1b20aa6264084ec2c8c3206e1c2d598 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 7 Mar 2011 14:01:37 -0800 Subject: fixing some tests on ruby 1.9.3 --- .../core_ext/date_time/calculations.rb | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'activesupport/lib/active_support/core_ext/date_time') 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 8d924ad420..48cf1a435d 100644 --- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb @@ -81,6 +81,29 @@ class DateTime change(:hour => 23, :min => 59, :sec => 59) end + # 1.9.3 defines + and - on DateTime, < 1.9.3 do not. + if DateTime.public_instance_methods(false).include?(:+) + def plus_with_duration(other) #:nodoc: + if ActiveSupport::Duration === other + other.since(self) + else + plus_without_duration(other) + end + end + alias_method :plus_without_duration, :+ + alias_method :+, :plus_with_duration + + def minus_with_duration(other) #:nodoc: + if ActiveSupport::Duration === other + plus_with_duration(-other) + else + minus_without_duration(other) + end + end + alias_method :minus_without_duration, :- + alias_method :-, :minus_with_duration + end + # Adjusts DateTime to UTC by adding its offset value; offset is set to 0 # # Example: -- cgit v1.2.3