mirror of
https://github.com/github/rails.git
synced 2026-01-30 00:38:00 -05:00
Removing unneeded #change_time_zone method from Time, DateTime and TimeWithZone
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9008 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Removing unneeded #change_time_zone method from Time, DateTime and TimeWithZone [Geoff Buesing]
|
||||
|
||||
* TimeZone #local and #now correctly enforce DST rules [Geoff Buesing]
|
||||
|
||||
* TimeWithZone instances correctly enforce DST rules. Adding TimeZone#period_for_utc [Geoff Buesing]
|
||||
|
||||
@@ -56,19 +56,6 @@ module ActiveSupport #:nodoc:
|
||||
def in_current_time_zone
|
||||
::Time.zone ? in_time_zone(::Time.zone) : self
|
||||
end
|
||||
|
||||
# Replaces the existing zone; leaves time values intact. Examples:
|
||||
#
|
||||
# t = Time.utc(2000) # => Sat Jan 01 00:00:00 UTC 2000
|
||||
# t.change_time_zone('Alaska') # => Sat, 01 Jan 2000 00:00:00 AKST -09:00
|
||||
# t.change_time_zone('Hawaii') # => Sat, 01 Jan 2000 00:00:00 HST -10:00
|
||||
#
|
||||
# Note the difference between this method and #in_time_zone: #in_time_zone does a calculation to determine
|
||||
# the simultaneous time in the supplied zone, whereas #change_time_zone does no calculation; it just
|
||||
# "dials in" a new time zone for +self+
|
||||
def change_time_zone(zone)
|
||||
ActiveSupport::TimeWithZone.new(nil, get_zone(zone), self)
|
||||
end
|
||||
|
||||
private
|
||||
def get_zone(time_zone)
|
||||
|
||||
@@ -41,11 +41,6 @@ module ActiveSupport
|
||||
utc.in_current_time_zone
|
||||
end
|
||||
|
||||
# Changes the time zone without converting the time
|
||||
def change_time_zone(new_zone)
|
||||
time.change_time_zone(new_zone)
|
||||
end
|
||||
|
||||
# Returns a Time.local() instance of the simultaneous time in your system's ENV['TZ'] zone
|
||||
def localtime
|
||||
utc.getlocal
|
||||
|
||||
@@ -36,12 +36,6 @@ uses_tzinfo 'TimeWithZoneTest' do
|
||||
end
|
||||
end
|
||||
|
||||
def test_change_time_zone
|
||||
silence_warnings do # silence warnings raised by tzinfo gem
|
||||
assert_equal ActiveSupport::TimeWithZone.new(nil, TimeZone['Alaska'], Time.utc(1999, 12, 31, 19)), @twz.change_time_zone('Alaska')
|
||||
end
|
||||
end
|
||||
|
||||
def test_utc?
|
||||
assert_equal false, @twz.utc?
|
||||
assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000), TimeZone['UTC']).utc?
|
||||
@@ -53,8 +47,10 @@ uses_tzinfo 'TimeWithZoneTest' do
|
||||
end
|
||||
|
||||
def test_dst?
|
||||
assert_equal false, @twz.dst?
|
||||
assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000, 6), @time_zone).dst?
|
||||
silence_warnings do # silence warnings raised by tzinfo gem
|
||||
assert_equal false, @twz.dst?
|
||||
assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000, 6), @time_zone).dst?
|
||||
end
|
||||
end
|
||||
|
||||
def test_zone
|
||||
@@ -295,30 +291,18 @@ uses_tzinfo 'TimeWithZoneTest' do
|
||||
end
|
||||
|
||||
def test_in_current_time_zone
|
||||
Time.use_zone 'Alaska' do
|
||||
assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @t.in_current_time_zone.inspect
|
||||
assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @dt.in_current_time_zone.inspect
|
||||
end
|
||||
Time.use_zone 'Hawaii' do
|
||||
assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @t.in_current_time_zone.inspect
|
||||
assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @dt.in_current_time_zone.inspect
|
||||
end
|
||||
Time.use_zone nil do
|
||||
assert_equal @t, @t.in_current_time_zone
|
||||
assert_equal @dt, @dt.in_current_time_zone
|
||||
end
|
||||
end
|
||||
|
||||
def test_change_time_zone
|
||||
silence_warnings do # silence warnings raised by tzinfo gem
|
||||
Time.use_zone 'Eastern Time (US & Canada)' do # Time.zone will not affect #change_time_zone(zone)
|
||||
assert_equal 'Sat, 01 Jan 2000 00:00:00 AKST -09:00', @t.change_time_zone('Alaska').inspect
|
||||
assert_equal 'Sat, 01 Jan 2000 00:00:00 AKST -09:00', @dt.change_time_zone('Alaska').inspect
|
||||
assert_equal 'Sat, 01 Jan 2000 00:00:00 HST -10:00', @t.change_time_zone('Hawaii').inspect
|
||||
assert_equal 'Sat, 01 Jan 2000 00:00:00 HST -10:00', @dt.change_time_zone('Hawaii').inspect
|
||||
assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @t.change_time_zone('UTC').inspect
|
||||
assert_equal 'Sat, 01 Jan 2000 00:00:00 UTC +00:00', @dt.change_time_zone('UTC').inspect
|
||||
assert_equal 'Sat, 01 Jan 2000 00:00:00 AKST -09:00', @t.change_time_zone(-9.hours).inspect
|
||||
Time.use_zone 'Alaska' do
|
||||
assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @t.in_current_time_zone.inspect
|
||||
assert_equal 'Fri, 31 Dec 1999 15:00:00 AKST -09:00', @dt.in_current_time_zone.inspect
|
||||
end
|
||||
Time.use_zone 'Hawaii' do
|
||||
assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @t.in_current_time_zone.inspect
|
||||
assert_equal 'Fri, 31 Dec 1999 14:00:00 HST -10:00', @dt.in_current_time_zone.inspect
|
||||
end
|
||||
Time.use_zone nil do
|
||||
assert_equal @t, @t.in_current_time_zone
|
||||
assert_equal @dt, @dt.in_current_time_zone
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user