diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2012-05-18 14:10:25 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2012-05-18 14:10:25 -0700 |
commit | 40bdf553a047c9b397cacd04cfcc6328381de3c0 (patch) | |
tree | ecc3ec0f522cb8998a8bb2fe4ec172ec24898a5f /activesupport/lib | |
parent | 8b4ecbebaa402610d1a21bb012efdbb24da1d110 (diff) | |
parent | dcdde7da481e11660634278a8004175a1ce20f39 (diff) | |
download | rails-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')
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 8 | ||||
-rw-r--r-- | activesupport/lib/active_support/time_with_zone.rb | 15 |
2 files changed, 16 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index a0f610d60c..92b8417150 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -253,7 +253,7 @@ class Time :hour => 23, :min => 59, :sec => 59, - :usec => 999999.999 + :usec => Rational(999999999, 1000) ) end @@ -268,7 +268,7 @@ class Time change( :min => 59, :sec => 59, - :usec => 999999.999 + :usec => Rational(999999999, 1000) ) end @@ -288,7 +288,7 @@ class Time :hour => 23, :min => 59, :sec => 59, - :usec => 999999.999 + :usec => Rational(999999999, 1000) ) end alias :at_end_of_month :end_of_month @@ -321,7 +321,7 @@ class Time :hour => 23, :min => 59, :sec => 59, - :usec => 999999.999 + :usec => Rational(999999999, 1000) ) end alias :at_end_of_year :end_of_year 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 |