Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8849

Show
Ignore:
Timestamp:
02/10/08 18:45:55 (7 months ago)
Author:
gbuesing
Message:

Time#in_time_zone handles Time.local instances correctly

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/CHANGELOG

    r8848 r8849  
    11*SVN* 
     2 
     3* Time#in_time_zone handles Time.local instances correctly [Geoff Buesing] 
    24 
    35* Pruning unneeded Time#change_time_zone_to_current. Enhanced docs to #change_time_zone to explain the difference between this method and #in_time_zone [Geoff Buesing] 
  • trunk/activesupport/lib/active_support/core_ext/time/zones.rb

    r8848 r8849  
    4343        end 
    4444         
    45         # Returns the simultaneous time in the supplied zone. self is assumed to be in UTC regardless of constructor. 
    46         # 
    47         # Examples: 
     45        # Returns the simultaneous time in the supplied zone. Examples: 
    4846        # 
    4947        #   t = Time.utc(2000)        # => Sat Jan 01 00:00:00 UTC 2000 
     
    5149        #   t.in_time_zone('Hawaii')  # => Fri, 31 Dec 1999 14:00:00 HST -10:00 
    5250        def in_time_zone(zone) 
    53           ActiveSupport::TimeWithZone.new(self, get_zone(zone)) 
     51          ActiveSupport::TimeWithZone.new(utc? ? self : getutc, get_zone(zone)) 
    5452        end 
    5553 
  • trunk/activesupport/test/core_ext/time_with_zone_test.rb

    r8848 r8849  
    175175      end 
    176176    end 
     177     
     178    def test_in_time_zone_with_time_local_instance 
     179      silence_warnings do # silence warnings raised by tzinfo gem 
     180        with_env_tz 'US/Eastern' do 
     181          time = Time.local(1999, 12, 31, 19) # == Time.utc(2000) 
     182          assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', time.in_time_zone('Alaska').inspect 
     183        end 
     184      end 
     185    end 
    177186 
    178187    def test_in_current_time_zone 
     
    229238      end 
    230239    end 
     240     
     241    protected 
     242      def with_env_tz(new_tz = 'US/Eastern') 
     243        old_tz, ENV['TZ'] = ENV['TZ'], new_tz 
     244        yield 
     245      ensure 
     246        old_tz ? ENV['TZ'] = old_tz : ENV.delete('TZ') 
     247      end 
    231248  end 
    232249end