aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorVasiliy Ermolovich <younash@gmail.com>2012-05-06 23:33:12 +0300
committerVasiliy Ermolovich <younash@gmail.com>2012-05-17 08:24:42 +0300
commite2e513621d732abb8efff9120bd9a444836720d6 (patch)
tree79ae1396eb2184bf1a8dafe5278a6146308688bc /activesupport/lib
parenta29bc1cf7b8580a815523e4c3a79e931f03ab8c2 (diff)
downloadrails-e2e513621d732abb8efff9120bd9a444836720d6.tar.gz
rails-e2e513621d732abb8efff9120bd9a444836720d6.tar.bz2
rails-e2e513621d732abb8efff9120bd9a444836720d6.zip
wrap time ranges with timezones, closes #6179
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/time_with_zone.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb
index 120b2a4c28..75fbd98b05 100644
--- a/activesupport/lib/active_support/time_with_zone.rb
+++ b/activesupport/lib/active_support/time_with_zone.rb
@@ -319,8 +319,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
@@ -344,5 +343,15 @@ module ActiveSupport
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