class TZInfo::TimezoneProxy - tzinfo-0.3.42 Documentation

# class TZInfo::TimezoneProxy

A proxy class representing a timezone with a given identifier. TimezoneProxy inherits from Timezone and can be treated like any Timezone loaded with TZInfo::Timezone.get.

The first time an attempt is made to access the data for the timezone, the real Timezone is loaded. If the proxy's identifier was not valid, then an exception will be raised at this point.

### Public Class Methods

_load(data) click to toggle source

Loads a marshalled TimezoneProxy.

    # File lib/tzinfo/timezone_proxy.rb, line 69
    def self._load(data)
      TimezoneProxy.new(data)
    end

new(identifier) click to toggle source

Construct a new TimezoneProxy for the given identifier. The identifier is not checked when constructing the proxy. It will be validated on the when the real Timezone is loaded.

Calls superclass method TZInfo::Timezone.new

    # File lib/tzinfo/timezone_proxy.rb, line 36
    def self.new(identifier)
      # Need to override new to undo the behaviour introduced in Timezone#new.
      tzp = super()
      tzp.send(:setup, identifier)
      tzp
    end

### Public Instance Methods

_dump(limit) click to toggle source

Dumps this TimezoneProxy for marshalling.

    # File lib/tzinfo/timezone_proxy.rb, line 64
    def _dump(limit)
      identifier
    end

identifier() click to toggle source

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

    # File lib/tzinfo/timezone_proxy.rb, line 44
    def identifier
      @real_timezone ? @real_timezone.identifier : @identifier
    end

period_for_utc(utc) click to toggle source

Returns the TimezonePeriod for the given UTC time. utc can either be a DateTime, Time or integer timestamp (Time.to_i). Any timezone information in utc is ignored (it is treated as a UTC time).

    # File lib/tzinfo/timezone_proxy.rb, line 51
    def period_for_utc(utc)
      real_timezone.period_for_utc(utc)
    end

periods_for_local(local) click to toggle source

Returns the set of TimezonePeriod instances that are valid for the given local time as an array. If you just want a single period, use period_for_local instead and specify how abiguities should be resolved. Returns an empty array if no periods are found for the given time.

    # File lib/tzinfo/timezone_proxy.rb, line 59
    def periods_for_local(local)
      real_timezone.periods_for_local(local)
    end

### Private Instance Methods

real_timezone() click to toggle source

    # File lib/tzinfo/timezone_proxy.rb, line 79
    def real_timezone
      @real_timezone ||= Timezone.get(@identifier)
    end

setup(identifier) click to toggle source

    # File lib/tzinfo/timezone_proxy.rb, line 74
    def setup(identifier)
      @identifier = identifier
      @real_timezone = nil
    end