Skip to content

Commit 33f222b

Browse files
committed
fixing some tests on ruby 1.9.3
1 parent a0d7247 commit 33f222b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

activesupport/lib/active_support/core_ext/date_time/calculations.rb

+23
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,29 @@ def end_of_day
8181
change(:hour => 23, :min => 59, :sec => 59)
8282
end
8383

84+
# 1.9.3 defines + and - on DateTime, < 1.9.3 do not.
85+
if DateTime.public_instance_methods(false).include?(:+)
86+
def plus_with_duration(other) #:nodoc:
87+
if ActiveSupport::Duration === other
88+
other.since(self)
89+
else
90+
plus_without_duration(other)
91+
end
92+
end
93+
alias_method :plus_without_duration, :+
94+
alias_method :+, :plus_with_duration
95+
96+
def minus_with_duration(other) #:nodoc:
97+
if ActiveSupport::Duration === other
98+
plus_with_duration(-other)
99+
else
100+
minus_without_duration(other)
101+
end
102+
end
103+
alias_method :minus_without_duration, :-
104+
alias_method :-, :minus_with_duration
105+
end
106+
84107
# Adjusts DateTime to UTC by adding its offset value; offset is set to 0
85108
#
86109
# Example:

0 commit comments

Comments
 (0)