Changeset 9008
- Timestamp:
- 03/11/08 06:23:41 (7 months ago)
- Files:
-
- trunk/activesupport/CHANGELOG (modified) (1 diff)
- trunk/activesupport/lib/active_support/core_ext/time/zones.rb (modified) (1 diff)
- trunk/activesupport/lib/active_support/time_with_zone.rb (modified) (1 diff)
- trunk/activesupport/test/core_ext/time_with_zone_test.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/CHANGELOG
r9007 r9008 1 1 *SVN* 2 3 * Removing unneeded #change_time_zone method from Time, DateTime and TimeWithZone [Geoff Buesing] 2 4 3 5 * TimeZone #local and #now correctly enforce DST rules [Geoff Buesing] trunk/activesupport/lib/active_support/core_ext/time/zones.rb
r8850 r9008 57 57 ::Time.zone ? in_time_zone(::Time.zone) : self 58 58 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 200063 # t.change_time_zone('Alaska') # => Sat, 01 Jan 2000 00:00:00 AKST -09:0064 # t.change_time_zone('Hawaii') # => Sat, 01 Jan 2000 00:00:00 HST -10:0065 #66 # Note the difference between this method and #in_time_zone: #in_time_zone does a calculation to determine67 # the simultaneous time in the supplied zone, whereas #change_time_zone does no calculation; it just68 # "dials in" a new time zone for +self+69 def change_time_zone(zone)70 ActiveSupport::TimeWithZone.new(nil, get_zone(zone), self)71 end72 59 73 60 private trunk/activesupport/lib/active_support/time_with_zone.rb
r9006 r9008 40 40 def in_current_time_zone 41 41 utc.in_current_time_zone 42 end43 44 # Changes the time zone without converting the time45 def change_time_zone(new_zone)46 time.change_time_zone(new_zone)47 42 end 48 43 trunk/activesupport/test/core_ext/time_with_zone_test.rb
r9006 r9008 37 37 end 38 38 39 def test_change_time_zone40 silence_warnings do # silence warnings raised by tzinfo gem41 assert_equal ActiveSupport::TimeWithZone.new(nil, TimeZone['Alaska'], Time.utc(1999, 12, 31, 19)), @twz.change_time_zone('Alaska')42 end43 end44 45 39 def test_utc? 46 40 assert_equal false, @twz.utc? … … 54 48 55 49 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 58 54 end 59 55 … … 296 292 297 293 def test_in_current_time_zone 298 Time.use_zone 'Alaska' do299 assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @t.in_current_time_zone.inspect300 assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @dt.in_current_time_zone.inspect301 end302 Time.use_zone 'Hawaii' do303 assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @t.in_current_time_zone.inspect304 assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @dt.in_current_time_zone.inspect305 end306 Time.use_zone nil do307 assert_equal @t, @t.in_current_time_zone308 assert_equal @dt, @dt.in_current_time_zone309 end310 end311 312 def test_change_time_zone313 294 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 322 306 end 323 307 end