Class: TZInfo::TimezoneProxy
- Defined in:
- lib/tzinfo/timezone.rb
Overview
A proxy class representing a timezone with a given identifier. It can be constructed with an identifier and behaves almost identically to a Timezone loaded through Timezone.get. The first time an attempt is made to perform a conversion on the proxy, the real Timezone class is loaded. If the proxy’s identifier was not valid, then an exception will be thrown at this point.
Class Method Summary collapse
-
.new(identifier) ⇒ Object
Construct a new TimezoneProxy for the given identifier.
Instance Method Summary collapse
-
#identifier ⇒ Object
The identifier of the timezone, e.g.
-
#periods ⇒ Object
:nodoc:.
Methods inherited from Timezone
#<=>, #==, all, all_country_zone_identifiers, all_country_zones, all_identifiers, #current_period, #current_period_and_time, #friendly_identifier, get, #local_to_utc, #name, #now, #period_for_local, #period_for_utc, #to_s, us_zone_identifiers, us_zones, #utc_to_local
Class Method Details
.new(identifier) ⇒ Object
Construct a new TimezoneProxy for the given identifier. The identifier is not checked when constructing the proxy. It will be validated on the first conversion.
423 424 425 426 427 428 429 430 431 |
# File 'lib/tzinfo/timezone.rb', line 423 def self.new(identifier) # Need to override new to undo the behaviour introduced in Timezone#new. tzp = super() tzp.instance_eval " @identifier = identifier\n @real_tz = nil\n" tzp end |
Instance Method Details
#identifier ⇒ Object
The identifier of the timezone, e.g. “Europe/Paris”.
434 435 436 |
# File 'lib/tzinfo/timezone.rb', line 434 def identifier @real_tz.nil? ? @identifier : @real_tz.identifier end |
#periods ⇒ Object
:nodoc:
438 439 440 441 442 443 444 |
# File 'lib/tzinfo/timezone.rb', line 438 def periods #:nodoc: if @real_tz.nil? # We now need the actual data. Load in the real timezone. @real_tz = Timezone.get(@identifier) end @real_tz.periods end |