class TZInfo::TimezoneProxy
A proxy class standing in for a {Timezone} with a given identifier. {TimezoneProxy} inherits from {Timezone} and can be treated identically to {Timezone} instances loaded with {Timezone.get}.
{TimezoneProxy} instances are used to avoid the performance overhead of loading time zone data into memory, for example, by {Timezone.all}.
The first time an attempt is made to access the data for the time zone, the real {Timezone} will be loaded is loaded. If the proxy’s identifier was not valid, then an exception will be raised at this point.
Public Class Methods
Loads a {TimezoneProxy} from the serialized representation returned by {_dump}. This is method is called when using ‘Marshal.load` or `Marshal.restore` to restore a serialized {Timezone}.
@param data [String] a serialized representation of a {TimezoneProxy}. @return [TimezoneProxy] the result of converting ‘data` back into a
{TimezoneProxy}.
# File lib/tzinfo/timezone_proxy.rb, line 71 def self._load(data) TimezoneProxy.new(data) end
Initializes a new {TimezoneProxy}.
The ‘identifier` parameter is not checked when initializing the proxy. It will be validated when the real {Timezone} instance is loaded.
@param identifier [String] an IANA Time Zone Database time zone
identifier.
# File lib/tzinfo/timezone_proxy.rb, line 23 def initialize(identifier) super() @identifier = identifier @real_timezone = nil end
Public Instance Methods
Returns a serialized representation of this {TimezoneProxy}. This method is called when using ‘Marshal.dump` with an instance of {TimezoneProxy}.
@param limit [Integer] the maximum depth to dump - ignored. @return
[String] a serialized representation of this {TimezoneProxy}.
@return [String] a serialized representation of this {TimezoneProxy}.
# File lib/tzinfo/timezone_proxy.rb, line 60 def _dump(limit) identifier end
(see Timezone#canonical_zone
)
# File lib/tzinfo/timezone_proxy.rb, line 50 def canonical_zone real_timezone.canonical_zone end
(see Timezone#identifier
)
# File lib/tzinfo/timezone_proxy.rb, line 30 def identifier @real_timezone ? @real_timezone.identifier : @identifier end
(see Timezone#period_for
)
# File lib/tzinfo/timezone_proxy.rb, line 35 def period_for(time) real_timezone.period_for_utc(time) end
(see Timezone#periods_for_local
)
# File lib/tzinfo/timezone_proxy.rb, line 40 def periods_for_local(local_time) real_timezone.periods_for_local(local_time) end
(see Timezone#transitions_up_to
)
# File lib/tzinfo/timezone_proxy.rb, line 45 def transitions_up_to(to, from = nil) real_timezone.transitions_up_to(to, from) end