From 276c9f29cde80fafa23814b0039f67504255e0fd Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Mon, 15 Jan 2007 06:54:50 +0000 Subject: Make 1.months and friends accurate by introducing a Duration class. #6835 [eventualbuddha] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5940 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../active_support/core_ext/time/calculations.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'activesupport/lib/active_support/core_ext/time') diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index cd412368dc..70a4768d13 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -5,6 +5,11 @@ module ActiveSupport #:nodoc: module Calculations def self.included(base) #:nodoc: base.extend(ClassMethods) + + base.send(:alias_method, :plus_without_duration, :+) + base.send(:alias_method, :+, :plus_with_duration) + base.send(:alias_method, :minus_without_duration, :-) + base.send(:alias_method, :-, :minus_with_duration) end module ClassMethods @@ -190,6 +195,22 @@ module ActiveSupport #:nodoc: def tomorrow self.since(1.day) end + + def plus_with_duration(other) #:nodoc: + if ActiveSupport::Duration === other + other.since(self) + else + plus_without_duration(other) + end + end + + def minus_with_duration(other) #:nodoc: + if ActiveSupport::Duration === other + other.until(self) + else + minus_without_duration(other) + end + end end end end -- cgit v1.2.3