diff options
author | Michael Koziarski <michael@koziarski.com> | 2007-01-15 06:54:50 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2007-01-15 06:54:50 +0000 |
commit | 276c9f29cde80fafa23814b0039f67504255e0fd (patch) | |
tree | 15a17ddcaff52bd1aaabf70281dbe7c7ac2d1433 /activesupport/lib/active_support/core_ext/time | |
parent | 51d840e272941023ad62d021fa2b4a491fe9953a (diff) | |
download | rails-276c9f29cde80fafa23814b0039f67504255e0fd.tar.gz rails-276c9f29cde80fafa23814b0039f67504255e0fd.tar.bz2 rails-276c9f29cde80fafa23814b0039f67504255e0fd.zip |
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
Diffstat (limited to 'activesupport/lib/active_support/core_ext/time')
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 21 |
1 files changed, 21 insertions, 0 deletions
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 |