mirror of
https://github.com/github/rails.git
synced 2026-01-28 15:58:03 -05:00
Time.get_zone refactored to private method, given that the encapsulated logic is only useful internally
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8719 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -28,15 +28,16 @@ module ActiveSupport #:nodoc:
|
||||
|
||||
# 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 @@ module ActiveSupport #:nodoc:
|
||||
# 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 @@ module ActiveSupport #:nodoc:
|
||||
# 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
|
||||
|
||||
Reference in New Issue
Block a user