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

Changeset 9008

Show
Ignore:
Timestamp:
03/11/08 06:23:41 (7 months ago)
Author:
gbuesing
Message:

Removing unneeded #change_time_zone method from Time, DateTime and TimeWithZone

Files:

Legend:

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

    r9007 r9008  
    11*SVN* 
     2 
     3* Removing unneeded #change_time_zone method from Time, DateTime and TimeWithZone [Geoff Buesing] 
    24 
    35* TimeZone #local and #now correctly enforce DST rules [Geoff Buesing] 
  • trunk/activesupport/lib/active_support/core_ext/time/zones.rb

    r8850 r9008  
    5757          ::Time.zone ? in_time_zone(::Time.zone) : self 
    5858        end 
    59  
    60         # Replaces the existing zone; leaves time values intact. Examples: 
    61         # 
    62         #   t = Time.utc(2000)            # => Sat Jan 01 00:00:00 UTC 2000 
    63         #   t.change_time_zone('Alaska')  # => Sat, 01 Jan 2000 00:00:00 AKST -09:00 
    64         #   t.change_time_zone('Hawaii')  # => Sat, 01 Jan 2000 00:00:00 HST -10:00 
    65         # 
    66         # Note the difference between this method and #in_time_zone: #in_time_zone does a calculation to determine 
    67         # the simultaneous time in the supplied zone, whereas #change_time_zone does no calculation; it just 
    68         # "dials in" a new time zone for +self+ 
    69         def change_time_zone(zone) 
    70           ActiveSupport::TimeWithZone.new(nil, get_zone(zone), self) 
    71         end 
    7259         
    7360        private 
  • trunk/activesupport/lib/active_support/time_with_zone.rb

    r9006 r9008  
    4040    def in_current_time_zone 
    4141      utc.in_current_time_zone 
    42     end 
    43    
    44     # Changes the time zone without converting the time 
    45     def change_time_zone(new_zone) 
    46       time.change_time_zone(new_zone) 
    4742    end 
    4843   
  • trunk/activesupport/test/core_ext/time_with_zone_test.rb

    r9006 r9008  
    3737    end 
    3838   
    39     def test_change_time_zone 
    40       silence_warnings do # silence warnings raised by tzinfo gem 
    41         assert_equal ActiveSupport::TimeWithZone.new(nil, TimeZone['Alaska'], Time.utc(1999, 12, 31, 19)), @twz.change_time_zone('Alaska') 
    42       end 
    43     end 
    44    
    4539    def test_utc? 
    4640      assert_equal false, @twz.utc? 
     
    5448       
    5549    def test_dst? 
    56       assert_equal false, @twz.dst? 
    57       assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000, 6), @time_zone).dst? 
     50      silence_warnings do # silence warnings raised by tzinfo gem 
     51        assert_equal false, @twz.dst? 
     52        assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000, 6), @time_zone).dst? 
     53      end 
    5854    end 
    5955       
     
    296292 
    297293    def test_in_current_time_zone 
    298       Time.use_zone 'Alaska' do 
    299         assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @t.in_current_time_zone.inspect 
    300         assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @dt.in_current_time_zone.inspect 
    301       end 
    302       Time.use_zone 'Hawaii' do 
    303         assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @t.in_current_time_zone.inspect 
    304         assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @dt.in_current_time_zone.inspect 
    305       end 
    306       Time.use_zone nil do 
    307         assert_equal @t, @t.in_current_time_zone 
    308         assert_equal @dt, @dt.in_current_time_zone 
    309       end 
    310     end 
    311      
    312     def test_change_time_zone 
    313294      silence_warnings do # silence warnings raised by tzinfo gem 
    314         Time.use_zone 'Eastern Time (US & Canada)' do # Time.zone will not affect #change_time_zone(zone) 
    315           assert_equal 'Sat, 01 Jan 2000 00:00:00 AKST -09:00', @t.change_time_zone('Alaska').inspect 
    316           assert_equal 'Sat, 01 Jan 2000 00:00:00 AKST -09:00', @dt.change_time_zone('Alaska').inspect 
    317           assert_equal 'Sat, 01 Jan 2000 00:00:00 HST -10:00', @t.change_time_zone('Hawaii').inspect 
    318           assert_equal 'Sat, 01 Jan 2000 00:00:00 HST -10:00', @dt.change_time_zone('Hawaii').inspect 
    319           assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @t.change_time_zone('UTC').inspect 
    320           assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @dt.change_time_zone('UTC').inspect 
    321           assert_equal 'Sat, 01 Jan 2000 00:00:00 AKST -09:00', @t.change_time_zone(-9.hours).inspect 
     295        Time.use_zone 'Alaska' do 
     296          assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @t.in_current_time_zone.inspect 
     297          assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @dt.in_current_time_zone.inspect 
     298        end 
     299        Time.use_zone 'Hawaii' do 
     300          assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @t.in_current_time_zone.inspect 
     301          assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @dt.in_current_time_zone.inspect 
     302        end 
     303        Time.use_zone nil do 
     304          assert_equal @t, @t.in_current_time_zone 
     305          assert_equal @dt, @dt.in_current_time_zone 
    322306        end 
    323307      end