0
-# Copyright (c) 2005-2006 Philip Ross
0
-# Permission is hereby granted, free of charge, to any person obtaining a copy
0
-# of this software and associated documentation files (the "Software"), to deal
0
-# in the Software without restriction, including without limitation the rights
0
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0
-# copies of the Software, and to permit persons to whom the Software is
0
-# furnished to do so, subject to the following conditions:
0
-# The above copyright notice and this permission notice shall be included in all
0
-# copies or substantial portions of the Software.
0
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
0
-require 'tzinfo/timezone'
0
- # A proxy class representing a timezone with a given identifier. TimezoneProxy
0
- # inherits from Timezone and can be treated like any Timezone loaded with
0
- # The first time an attempt is made to access the data for the timezone, the
0
- # real Timezone is loaded. If the proxy's identifier was not valid, then an
0
- # exception will be raised at this point.
0
- class TimezoneProxy < Timezone
0
- # Construct a new TimezoneProxy for the given identifier. The identifier
0
- # is not checked when constructing the proxy. It will be validated on the
0
- # when the real Timezone is loaded.
0
- def self.new(identifier)
0
- # Need to override new to undo the behaviour introduced in Timezone#new.
0
- tzp.send(:setup, identifier)
0
- # The identifier of the timezone, e.g. "Europe/Paris".
0
- @real_timezone ? @real_timezone.identifier : @identifier
0
- # Returns the TimezonePeriod for the given UTC time. utc can either be
0
- # a DateTime, Time or integer timestamp (Time.to_i). Any timezone
0
- # information in utc is ignored (it is treated as a UTC time).
0
- def period_for_utc(utc)
0
- real_timezone.period_for_utc(utc)
0
- # Returns the set of TimezonePeriod instances that are valid for the given
0
- # local time as an array. If you just want a single period, use
0
- # period_for_local instead and specify how abiguities should be resolved.
0
- # Returns an empty array if no periods are found for the given time.
0
- def periods_for_local(local)
0
- real_timezone.periods_for_local(local)
0
- # Dumps this TimezoneProxy for marshalling.
0
- # Loads a marshalled TimezoneProxy.
0
- TimezoneProxy.new(data)
0
- @identifier = identifier
0
- @real_timezone ||= Timezone.get(@identifier)
Comments
No one has commented yet.