Class: TZInfo::TimezoneProxy

Inherits:
Timezone show all
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

Instance Method Summary collapse

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.



328
329
330
331
332
333
334
335
336
# File 'lib/tzinfo/timezone.rb', line 328

def self.new(identifier)
  # Need to override new to undo the behaviour introduced in Timezone#new.
  tzp = super()
  tzp.instance_eval <<CODE
    @identifier = identifier
    @real_tz = nil
CODE
  tzp
end

Instance Method Details

#identifierObject

The identifier of the timezone, e.g. “Europe/Paris”.



339
340
341
# File 'lib/tzinfo/timezone.rb', line 339

def identifier
  @real_tz.nil? ? @identifier : @real_tz.identifier
end

#periodsObject

:nodoc:



343
344
345
346
347
348
349
# File 'lib/tzinfo/timezone.rb', line 343

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