aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/time_with_zone.rb27
1 files changed, 18 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
index 1c984f07d4..f1a2498298 100644
--- a/activesupport/lib/active_support/time_with_zone.rb
+++ b/activesupport/lib/active_support/time_with_zone.rb
@@ -134,7 +134,8 @@ module ActiveSupport
# If wrapped #time is a DateTime, use DateTime#since instead of #+
# Otherwise, just pass on to #method_missing
def +(other)
- time.acts_like?(:date) ? method_missing(:since, other) : method_missing(:+, other)
+ result = utc.acts_like?(:date) ? utc.since(other) : utc + other
+ result.in_time_zone(time_zone)
end
# If a time-like object is passed in, compare it with #utc
@@ -144,10 +145,23 @@ module ActiveSupport
if other.acts_like?(:time)
utc - other
else
- time.acts_like?(:date) ? method_missing(:ago, other) : method_missing(:-, other)
+ result = utc.acts_like?(:date) ? utc.ago(other) : utc - other
+ result.in_time_zone(time_zone)
end
end
+ def since(other)
+ utc.since(other).in_time_zone(time_zone)
+ end
+
+ def ago(other)
+ utc.ago(other).in_time_zone(time_zone)
+ end
+
+ def advance(options)
+ utc.advance(options).in_time_zone(time_zone)
+ end
+
def usec
time.respond_to?(:usec) ? time.usec : 0
end
@@ -208,13 +222,8 @@ module ActiveSupport
# Send the missing method to time instance, and wrap result in a new TimeWithZone with the existing time_zone
def method_missing(sym, *args, &block)
- if %w(+ - since ago advance).include?(sym.to_s)
- result = utc.__send__(sym, *args, &block)
- result.acts_like?(:time) ? result.in_time_zone(time_zone) : result
- else
- result = time.__send__(sym, *args, &block)
- result.acts_like?(:time) ? self.class.new(nil, time_zone, result) : result
- end
+ result = time.__send__(sym, *args, &block)
+ result.acts_like?(:time) ? self.class.new(nil, time_zone, result) : result
end
private