Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Time.get_zone refactored to private method, given that the encapsulat…

…ed logic is only useful internally

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8719 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit a7adca3d3b53df69cf45756f0459e501ee44d469 1 parent c911e1a
@gbuesing gbuesing authored
View
2  activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Time.get_zone refactored to private method, given that the encapsulated logic is only useful internally [Geoff Buesing]
+
* Time.zone uses thread-local variable for thread safety. Adding Time.use_zone, for overriding Time.zone locally inside a block. Removing unneeded Time.zone_reset! [Geoff Buesing]
* TimeZone#to_s uses UTC rather than GMT; reapplying change that was undone in [8679]. #1689 [Cheah Chu Yeow]
View
18 activesupport/lib/active_support/core_ext/time/zones.rb
@@ -28,15 +28,16 @@ def zone=(time_zone)
# Allows override of Time.zone locally inside supplied block; resets Time.zone to existing value when done
def use_zone(time_zone)
- old_zone, ::Time.zone = ::Time.zone, ::Time.get_zone(time_zone)
+ old_zone, ::Time.zone = ::Time.zone, get_zone(time_zone)
yield
ensure
::Time.zone = old_zone
end
- def get_zone(time_zone)
- ::String === time_zone || ::Numeric === time_zone ? TimeZone[time_zone] : time_zone
- end
+ private
+ def get_zone(time_zone)
+ ::String === time_zone || ::Numeric === time_zone ? TimeZone[time_zone] : time_zone
+ end
end
# Gives the corresponding time in the supplied zone. self is assumed to be in UTC regardless of constructor.
@@ -47,7 +48,7 @@ def get_zone(time_zone)
# t.in_time_zone('Alaska') # => Fri, 31 Dec 1999 15:00:00 AKST -09:00
# t.in_time_zone('Hawaii') # => Fri, 31 Dec 1999 14:00:00 HST -10:00
def in_time_zone(zone)
- ActiveSupport::TimeWithZone.new(self, ::Time.get_zone(zone))
+ ActiveSupport::TimeWithZone.new(self, get_zone(zone))
end
# Returns the simultaneous time in Time.zone
@@ -61,13 +62,18 @@ def in_current_time_zone
# 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
def change_time_zone(zone)
- ActiveSupport::TimeWithZone.new(nil, ::Time.get_zone(zone), self)
+ 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)
+ ::Time.send!(:get_zone, time_zone)
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.