aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/core_ext/time/zones.rb13
-rw-r--r--activesupport/test/core_ext/time_with_zone_test.rb21
3 files changed, 8 insertions, 28 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 6b66875012..81c5574dbf 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* 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]
+
* TimeZone#new method renamed #local; when used with Time.zone, constructor now reads: Time.zone.local() [Geoff Buesing]
* Added Base64.encode64s to encode values in base64 without the newlines. This makes the values immediately usable as URL parameters or memcache keys without further processing [DHH]
diff --git a/activesupport/lib/active_support/core_ext/time/zones.rb b/activesupport/lib/active_support/core_ext/time/zones.rb
index 33c7800705..4705e93f27 100644
--- a/activesupport/lib/active_support/core_ext/time/zones.rb
+++ b/activesupport/lib/active_support/core_ext/time/zones.rb
@@ -42,7 +42,7 @@ module ActiveSupport #:nodoc:
end
end
- # Gives the corresponding time in the supplied zone. self is assumed to be in UTC regardless of constructor.
+ # Returns the simultaneous time in the supplied zone. self is assumed to be in UTC regardless of constructor.
#
# Examples:
#
@@ -58,19 +58,18 @@ module ActiveSupport #:nodoc:
::Time.zone ? in_time_zone(::Time.zone) : self
end
- # Replaces the existing zone; leaves time value intact. Examples:
+ # 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
-
- # Replaces the existing zone to Time.zone; leaves time value intact
- def change_time_zone_to_current
- ::Time.zone ? change_time_zone(::Time.zone) : self
- end
private
def get_zone(time_zone)
diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb
index eae4d3094e..3f0ec0720b 100644
--- a/activesupport/test/core_ext/time_with_zone_test.rb
+++ b/activesupport/test/core_ext/time_with_zone_test.rb
@@ -38,12 +38,6 @@ uses_tzinfo 'TimeWithZoneTest' do
end
end
- def test_change_time_zone_to_current
- Time.use_zone 'Alaska' do
- assert_equal ActiveSupport::TimeWithZone.new(nil, TimeZone['Alaska'], Time.utc(1999, 12, 31, 19)), @twz.change_time_zone_to_current
- end
- end
-
def test_utc?
assert_equal false, @twz.utc?
assert_equal true, ActiveSupport::TimeWithZone.new(Time.utc(2000), TimeZone['UTC']).utc?
@@ -209,21 +203,6 @@ uses_tzinfo 'TimeWithZoneTest' do
end
end
- def test_change_time_zone_to_current
- Time.use_zone 'Alaska' do
- assert_equal 'Sat, 01 Jan 2000 00:00:00 AKST -09:00', @t.change_time_zone_to_current.inspect
- assert_equal 'Sat, 01 Jan 2000 00:00:00 AKST -09:00', @dt.change_time_zone_to_current.inspect
- end
- Time.use_zone 'Hawaii' do
- assert_equal 'Sat, 01 Jan 2000 00:00:00 HST -10:00', @t.change_time_zone_to_current.inspect
- assert_equal 'Sat, 01 Jan 2000 00:00:00 HST -10:00', @dt.change_time_zone_to_current.inspect
- end
- Time.use_zone nil do
- assert_equal @t, @t.change_time_zone_to_current
- assert_equal @dt, @dt.change_time_zone_to_current
- end
- end
-
def test_use_zone
Time.zone = 'Alaska'
Time.use_zone 'Hawaii' do