Class: TZInfo::LinkedTimezone

Inherits:
InfoTimezone show all
Defined in:
lib/tzinfo/linked_timezone.rb

Overview

Represents time zones that are defined as a link to or alias for another time zone.

Instance Method Summary collapse

Methods inherited from InfoTimezone

#identifier, #info

Methods inherited from Timezone

#<=>, #=~, #_dump, _load, #abbreviation, all, all_country_zone_identifiers, all_country_zones, all_data_zone_identifiers, all_data_zones, all_identifiers, all_linked_zone_identifiers, all_linked_zones, #base_utc_offset, #canonical_identifier, #current_period, #current_time_and_period, default_dst, default_dst=, #dst?, #eql?, #friendly_identifier, get, get_proxy, #hash, #identifier, #inspect, #local_datetime, #local_time, #local_timestamp, #local_to_utc, #name, #now, #observed_utc_offset, #offsets_up_to, #period_for_local, #period_for_utc, #strftime, #to_local, #to_s, #utc_to_local

Constructor Details

#initialize(info) ⇒ LinkedTimezone

Initializes a new TZInfo::LinkedTimezone.

TZInfo::LinkedTimezone instances should not normally be created directly. Use the Timezone.get method to obtain Timezone instances.

Parameters:



15
16
17
18
# File 'lib/tzinfo/linked_timezone.rb', line 15

def initialize(info)
  super
  @linked_timezone = Timezone.get(info.link_to_identifier)
end

Instance Method Details

#canonical_zoneTimezone

Returns the canonical Timezone instance for this TZInfo::LinkedTimezone.

For a TZInfo::LinkedTimezone, this is the canonical zone of the link target.

Returns:



40
41
42
# File 'lib/tzinfo/linked_timezone.rb', line 40

def canonical_zone
  @linked_timezone.canonical_zone
end

#period_for(time) ⇒ TimezonePeriod

Returns the TimezonePeriod that is valid at a given time.

Unlike Timezone#period_for_local and Timezone#period_for_utc, the UTC offset of the time parameter is taken into consideration.

Parameters:

  • time (Object)

    a Time, DateTime or Timestamp.

Returns:

Raises:

  • (ArgumentError)

    if time is nil.

  • (ArgumentError)

    if time is a Timestamp with an unspecified offset.



21
22
23
# File 'lib/tzinfo/linked_timezone.rb', line 21

def period_for(time)
  @linked_timezone.period_for(time)
end

#periods_for_local(local_time) ⇒ Array<TimezonePeriod>

Returns the set of TimezonePeriods that are valid for the given local time as an Array.

The UTC offset of the local_time parameter is ignored (it is treated as a time in the time zone represented by self).

This will typically return an Array containing a single TimezonePeriod. More than one TimezonePeriod will be returned when the local time is ambiguous (for example, when daylight savings time ends). An empty Array will be returned when the local time is not valid (for example, when daylight savings time begins).

To obtain just a single TimezonePeriod in all cases, use Timezone#period_for_local instead and specify how ambiguities should be resolved.

Parameters:

  • local_time (Object)

    a Time, DateTime or Timestamp.

Returns:

Raises:

  • (ArgumentError)

    if local_time is nil.



26
27
28
# File 'lib/tzinfo/linked_timezone.rb', line 26

def periods_for_local(local_time)
  @linked_timezone.periods_for_local(local_time)
end

#transitions_up_to(to, from = nil) ⇒ Array<TimezoneTransition>

Returns an Array of TimezoneTransition instances representing the times where the UTC offset of the timezone changes.

Transitions are returned up to a given time (to).

A from time may also be supplied using the from parameter. If from is not nil, only transitions from that time onwards will be returned.

Comparisons with to are exclusive. Comparisons with from are inclusive. If a transition falls precisely on to, it will be excluded. If a transition falls on from, it will be included.

Parameters:

  • to (Object)

    a Time, DateTime or Timestamp specifying the latest (exclusive) transition to return.

  • from (Object) (defaults to: nil)

    an optional Time, DateTime or Timestamp specifying the earliest (inclusive) transition to return.

Returns:

  • (Array<TimezoneTransition>)

    the transitions that are earlier than to and, if specified, at or later than from. Transitions are ordered by when they occur, from earliest to latest.

Raises:

  • (ArgumentError)

    if from is specified and to is not greater than from.

  • (ArgumentError)

    is raised if to is nil.

  • (ArgumentError)

    if either to or from is a Timestamp with an unspecified offset.



31
32
33
# File 'lib/tzinfo/linked_timezone.rb', line 31

def transitions_up_to(to, from = nil)
  @linked_timezone.transitions_up_to(to, from)
end