diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-03-07 14:01:37 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-03-07 14:01:51 -0800 |
commit | 33f222b9e1b20aa6264084ec2c8c3206e1c2d598 (patch) | |
tree | f4e2ec8978759ef727a9e01a6212a6895236481b /activesupport/lib | |
parent | a0d7247d1509762283c61182ad82c2eed8d54757 (diff) | |
download | rails-33f222b9e1b20aa6264084ec2c8c3206e1c2d598.tar.gz rails-33f222b9e1b20aa6264084ec2c8c3206e1c2d598.tar.bz2 rails-33f222b9e1b20aa6264084ec2c8c3206e1c2d598.zip |
fixing some tests on ruby 1.9.3
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/date_time/calculations.rb | 23 |
1 files changed, 23 insertions, 0 deletions
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: |