aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/time_with_zone.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2012-05-18 14:10:25 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2012-05-18 14:10:25 -0700
commit40bdf553a047c9b397cacd04cfcc6328381de3c0 (patch)
treeecc3ec0f522cb8998a8bb2fe4ec172ec24898a5f /activesupport/lib/active_support/time_with_zone.rb
parent8b4ecbebaa402610d1a21bb012efdbb24da1d110 (diff)
parentdcdde7da481e11660634278a8004175a1ce20f39 (diff)
downloadrails-40bdf553a047c9b397cacd04cfcc6328381de3c0.tar.gz
rails-40bdf553a047c9b397cacd04cfcc6328381de3c0.tar.bz2
rails-40bdf553a047c9b397cacd04cfcc6328381de3c0.zip
Merge pull request #6183 from nashby/fix-issue-6179
wrap time ranges with timezones
Diffstat (limited to 'activesupport/lib/active_support/time_with_zone.rb')
-rw-r--r--activesupport/lib/active_support/time_with_zone.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
index 67ac1b6ccd..451520ac5c 100644
--- a/activesupport/lib/active_support/time_with_zone.rb
+++ b/activesupport/lib/active_support/time_with_zone.rb
@@ -317,8 +317,7 @@ 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)
- result = time.__send__(sym, *args, &block)
- result.acts_like?(:time) ? self.class.new(nil, time_zone, result) : result
+ wrap_with_time_zone time.__send__(sym, *args, &block)
end
private
@@ -336,11 +335,21 @@ module ActiveSupport
end
def transfer_time_values_to_utc_constructor(time)
- ::Time.utc_time(time.year, time.month, time.day, time.hour, time.min, time.sec, time.respond_to?(:usec) ? time.usec : 0)
+ ::Time.utc_time(time.year, time.month, time.day, time.hour, time.min, time.sec, time.respond_to?(:nsec) ? Rational(time.nsec, 1000) : 0)
end
def duration_of_variable_length?(obj)
ActiveSupport::Duration === obj && obj.parts.any? {|p| p[0].in?([:years, :months, :days]) }
end
+
+ def wrap_with_time_zone(time)
+ if time.acts_like?(:time)
+ self.class.new(nil, time_zone, time)
+ elsif time.is_a?(Range)
+ wrap_with_time_zone(time.begin)..wrap_with_time_zone(time.end)
+ else
+ time
+ end
+ end
end
end