Class: TZInfo::TimezoneProxy
- Defined in:
- lib/tzinfo/timezone_proxy.rb
Overview
A proxy class representing a timezone with a given identifier. TimezoneProxy inherits from Timezone and can be treated like any Timezone loaded with 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.
Class Method Summary collapse
-
._load(data) ⇒ Object
Loads a marshalled TimezoneProxy.
-
.new(identifier) ⇒ Object
Construct a new TimezoneProxy for the given identifier.
Instance Method Summary collapse
-
#_dump(limit) ⇒ Object
Dumps this TimezoneProxy for marshalling.
-
#canonical_zone ⇒ Object
Returns the canonical zone for this Timezone.
-
#identifier ⇒ Object
The identifier of the timezone, e.g.
-
#period_for_utc(utc) ⇒ Object
Returns the TimezonePeriod for the given UTC time.
-
#periods_for_local(local) ⇒ Object
Returns the set of TimezonePeriod instances that are valid for the given local time as an array.
Methods inherited from Timezone
#<=>, all, all_country_zone_identifiers, all_country_zones, all_data_zone_identifiers, all_data_zones, all_identifiers, all_linked_zone_identifiers, all_linked_zones, #canonical_identifier, #current_period, #current_period_and_time, default_dst, default_dst=, #eql?, #friendly_identifier, get, get_proxy, #hash, #inspect, #local_to_utc, #name, #now, #offsets_up_to, #period_for_local, #strftime, #to_s, #transitions_up_to, us_zone_identifiers, us_zones, #utc_to_local
Class Method Details
._load(data) ⇒ Object
Loads a marshalled TimezoneProxy.
52 53 54 |
# File 'lib/tzinfo/timezone_proxy.rb', line 52 def self._load(data) TimezoneProxy.new(data) end |
.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 when the real Timezone is loaded.
14 15 16 17 18 19 |
# File 'lib/tzinfo/timezone_proxy.rb', line 14 def self.new(identifier) # Need to override new to undo the behaviour introduced in Timezone#new. tzp = super() tzp.send(:setup, identifier) tzp end |
Instance Method Details
#_dump(limit) ⇒ Object
Dumps this TimezoneProxy for marshalling.
47 48 49 |
# File 'lib/tzinfo/timezone_proxy.rb', line 47 def _dump(limit) identifier end |
#canonical_zone ⇒ Object
Returns the canonical zone for this Timezone.
42 43 44 |
# File 'lib/tzinfo/timezone_proxy.rb', line 42 def canonical_zone real_timezone.canonical_zone end |
#identifier ⇒ Object
The identifier of the timezone, e.g. “Europe/Paris”.
22 23 24 |
# File 'lib/tzinfo/timezone_proxy.rb', line 22 def identifier @real_timezone ? @real_timezone.identifier : @identifier end |
#period_for_utc(utc) ⇒ Object
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).
29 30 31 |
# File 'lib/tzinfo/timezone_proxy.rb', line 29 def period_for_utc(utc) real_timezone.period_for_utc(utc) end |
#periods_for_local(local) ⇒ Object
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.
37 38 39 |
# File 'lib/tzinfo/timezone_proxy.rb', line 37 def periods_for_local(local) real_timezone.periods_for_local(local) end |