diff options
author | Vasiliy Ermolovich <younash@gmail.com> | 2012-05-06 23:33:12 +0300 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2013-01-08 10:33:45 +0000 |
commit | d39d878d2b250636256ecf54473d365ffb62eb6d (patch) | |
tree | a321d35ef170b65aaaa3da32dc7283ddf9687b61 /activesupport/lib/active_support/time_with_zone.rb | |
parent | d9a048001f869a3252cb85477f775de9860d615f (diff) | |
download | rails-d39d878d2b250636256ecf54473d365ffb62eb6d.tar.gz rails-d39d878d2b250636256ecf54473d365ffb62eb6d.tar.bz2 rails-d39d878d2b250636256ecf54473d365ffb62eb6d.zip |
Wrap time ranges with timezones, closes #8807
(cherry picked from commit e2e513621d732abb8efff9120bd9a444836720d6)
(cherry picked from commit dcdde7da481e11660634278a8004175a1ce20f39)
Backport of #6183, original issue was #6179
Conflicts:
activesupport/lib/active_support/core_ext/time/calculations.rb
activesupport/test/core_ext/time_ext_test
Signed-off-by: Andrew White <andyw@pixeltrix.co.uk>
Diffstat (limited to 'activesupport/lib/active_support/time_with_zone.rb')
-rw-r--r-- | activesupport/lib/active_support/time_with_zone.rb | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index a3c378f057..f39b58a980 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -329,8 +329,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 @@ -348,11 +347,22 @@ 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) + usec = time.respond_to?(:nsec) ? Rational(time.nsec, 1000) : (time.respond_to?(:usec) ? time.usec : 0) + ::Time.utc_time(time.year, time.month, time.day, time.hour, time.min, time.sec, usec) 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 |