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

Changeset 8848

Show
Ignore:
Timestamp:
02/10/08 18:20:37 (8 months ago)
Author:
gbuesing
Message:

Pruning unneeded Time#change_time_zone_to_current. Enhanced docs for #change_time_zone

Files:

Legend:

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

    r8847 r8848  
    11*SVN* 
     2 
     3* 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] 
    24 
    35* TimeZone#new method renamed #local; when used with Time.zone, constructor now reads: Time.zone.local() [Geoff Buesing] 
  • trunk/activesupport/lib/active_support/core_ext/time/zones.rb

    r8806 r8848  
    4343        end 
    4444         
    45         # Gives the corresponding time in the supplied zone. self is assumed to be in UTC regardless of constructor. 
     45        # Returns the simultaneous time in the supplied zone. self is assumed to be in UTC regardless of constructor. 
    4646        # 
    4747        # Examples: 
     
    5959        end 
    6060 
    61         # Replaces the existing zone; leaves time value intact. Examples: 
     61        # Replaces the existing zone; leaves time values intact. Examples: 
    6262        # 
    6363        #   t = Time.utc(2000)            # => Sat Jan 01 00:00:00 UTC 2000 
    6464        #   t.change_time_zone('Alaska')  # => Sat, 01 Jan 2000 00:00:00 AKST -09:00 
    6565        #   t.change_time_zone('Hawaii')  # => Sat, 01 Jan 2000 00:00:00 HST -10:00 
     66        # 
     67        # Note the difference between this method and #in_time_zone: #in_time_zone does a calculation to determine 
     68        # the simultaneous time in the supplied zone, whereas #change_time_zone does no calculation; it just 
     69        # "dials in" a new time zone for +self+ 
    6670        def change_time_zone(zone) 
    6771          ActiveSupport::TimeWithZone.new(nil, get_zone(zone), self) 
    68         end 
    69  
    70         # Replaces the existing zone to Time.zone; leaves time value intact 
    71         def change_time_zone_to_current 
    72           ::Time.zone ? change_time_zone(::Time.zone) : self 
    7372        end 
    7473         
  • trunk/activesupport/test/core_ext/time_with_zone_test.rb

    r8732 r8848  
    3636      silence_warnings do # silence warnings raised by tzinfo gem 
    3737        assert_equal ActiveSupport::TimeWithZone.new(nil, TimeZone['Alaska'], Time.utc(1999, 12, 31, 19)), @twz.change_time_zone('Alaska') 
    38       end 
    39     end 
    40    
    41     def test_change_time_zone_to_current 
    42       Time.use_zone 'Alaska' do 
    43         assert_equal ActiveSupport::TimeWithZone.new(nil, TimeZone['Alaska'], Time.utc(1999, 12, 31, 19)), @twz.change_time_zone_to_current 
    4438      end 
    4539    end 
     
    210204    end 
    211205     
    212     def test_change_time_zone_to_current 
    213       Time.use_zone 'Alaska' do 
    214         assert_equal 'Sat, 01 Jan 2000 00:00:00 AKST -09:00', @t.change_time_zone_to_current.inspect 
    215         assert_equal 'Sat, 01 Jan 2000 00:00:00 AKST -09:00', @dt.change_time_zone_to_current.inspect 
    216       end 
    217       Time.use_zone 'Hawaii' do 
    218         assert_equal 'Sat, 01 Jan 2000 00:00:00 HST -10:00', @t.change_time_zone_to_current.inspect 
    219         assert_equal 'Sat, 01 Jan 2000 00:00:00 HST -10:00', @dt.change_time_zone_to_current.inspect 
    220       end 
    221       Time.use_zone nil do 
    222         assert_equal @t, @t.change_time_zone_to_current 
    223         assert_equal @dt, @dt.change_time_zone_to_current 
    224       end 
    225     end 
    226      
    227206    def test_use_zone 
    228207      Time.zone = 'Alaska'