Home Reference Source
public class | source

TzdbZoneRules

Extends:

@js-joda/core~ZoneRules → TzdbZoneRules

Constructor Summary

Public Constructor
public

Method Summary

Public Methods
public

Gets the amount of daylight savings in use for the specified instant in this zone.

public

equals(other: *): boolean

public

isDaylightSavings(instant: Instant): boolean

Checks if the specified instant is in daylight savings.

public

isFixedOffset(): boolean

Checks of the zone rules are fixed, such that the offset never varies.

public

isValidOffset(localDateTime: LocalDateTime, offset: ZoneOffset): boolean

Checks if the offset date-time is valid for these rules.

public

Gets the next transition after the specified instant.

public

offsetOfEpochMilli(epochMilli: number): ZoneOffset

Gets the offset applicable at the specified epochMilli in these rules.

public

Gets the offset applicable at the specified instant in these rules.

public

Gets a suitable offset for the specified local date-time in these rules.

public

Gets the previous transition before the specified instant.

public

Gets the standard offset for the specified instant in this zone.

public

toString(): string

public

Gets the offset transition applicable at the specified local date-time in these rules.

public

Not supported, always throws.

public

Not supported, always throws.

public

validOffsets(localDateTime: LocalDateTime): ZoneOffsetTransition | ZoneOffset[]

Gets the offset applicable at the specified local date-time in these rules.

Public Constructors

public constructor() source

Public Methods

public daylightSavings(instant: Instant): Duration source

Gets the amount of daylight savings in use for the specified instant in this zone.

This provides access to historic information on how the amount of daylight savings has changed over time. This is the difference between the standard offset and the actual offset. Typically the amount is zero during winter and one hour during summer. Time-zones are second-based, so the nanosecond part of the duration will be zero.

Params:

NameTypeAttributeDescription
instant Instant

the instant to find the daylight savings for, not null, but null may be ignored if the rules have a single offset for all instants

Return:

Duration

the difference between the standard and actual offset, not null

Throw:

Error

if the tz data of the zone has no standard offsets

public equals(other: *): boolean source

Params:

NameTypeAttributeDescription
other *

Return:

boolean

public isDaylightSavings(instant: Instant): boolean source

Checks if the specified instant is in daylight savings.

This checks if the standard and actual offsets are the same at the specified instant.

Params:

NameTypeAttributeDescription
instant Instant

the instant to find the offset information for, not null, but null may be ignored if the rules have a single offset for all instants

Return:

boolean

true if the standard offset differs from the actual offset

Throw:

Error

if the tz data of the zone has no standard offsets

public isFixedOffset(): boolean source

Checks of the zone rules are fixed, such that the offset never varies.

Return:

boolean

true if the time-zone is fixed and the offset never changes

public isValidOffset(localDateTime: LocalDateTime, offset: ZoneOffset): boolean source

Checks if the offset date-time is valid for these rules.

To be valid, the local date-time must not be in a gap and the offset must match the valid offsets.

Params:

NameTypeAttributeDescription
localDateTime LocalDateTime

the date-time to check, not null, but null may be ignored if the rules have a single offset for all instants

offset ZoneOffset

the offset to check, null returns false

Return:

boolean

true if the offset date-time is valid for these rules

public nextTransition(instant: Instant): ZoneOffsetTransition source

Gets the next transition after the specified instant.

This returns details of the next transition after the specified instant. For example, if the instant represents a point where "Summer" daylight savings time applies, then the method will return the transition to the next "Winter" time.

Params:

NameTypeAttributeDescription
instant Instant

the instant to get the next transition after, not null, but null may be ignored if the rules have a single offset for all instants

Return:

ZoneOffsetTransition

the next transition after the specified instant, null if this is after the last transition

public offsetOfEpochMilli(epochMilli: number): ZoneOffset source

Gets the offset applicable at the specified epochMilli in these rules.

The method is for javascript performance optimisation.

Params:

NameTypeAttributeDescription
epochMilli number

the epoch millisecond to find the offset for, not null, but null may be ignored if the rules have a single offset for all instants

Return:

ZoneOffset

the offset, not null

public offsetOfInstant(instant: Instant): ZoneOffset source

Gets the offset applicable at the specified instant in these rules.

The mapping from an instant to an offset is simple, there is only one valid offset for each instant. This method returns that offset.

Params:

NameTypeAttributeDescription
instant Instant

the instant to find the offset for, not null, but null may be ignored if the rules have a single offset for all instants

Return:

ZoneOffset

the offset, not null

public offsetOfLocalDateTime(localDateTime: LocalDateTime): ZoneOffset source

Gets a suitable offset for the specified local date-time in these rules.

The mapping from a local date-time to an offset is not straightforward. There are three cases:

  • Normal, with one valid offset. For the vast majority of the year, the normal case applies, where there is a single valid offset for the local date-time.
  • Gap, with zero valid offsets. This is when clocks jump forward typically due to the spring daylight savings change from "winter" to "summer". In a gap there are local date-time values with no valid offset.
  • Overlap, with two valid offsets. This is when clocks are set back typically due to the autumn daylight savings change from "summer" to "winter". In an overlap there are local date-time values with two valid offsets.
  • Thus, for any given local date-time there can be zero, one or two valid offsets. This method returns the single offset in the Normal case, and in the Gap or Overlap case it returns the offset before the transition.

    Since, in the case of Gap and Overlap, the offset returned is a "best" value, rather than the "correct" value, it should be treated with care. Applications that care about the correct offset should use a combination of this method, {@link #getValidOffsets(LocalDateTime)} and {@link #getTransition(LocalDateTime)}.

    Params:

    NameTypeAttributeDescription
    localDateTime LocalDateTime

    the local date-time to query, not null, but null may be ignored if the rules have a single offset for all instants

    Return:

    ZoneOffset

    the best available offset for the local date-time, not null

    public previousTransition(instant: Instant): ZoneOffsetTransition source

    Gets the previous transition before the specified instant.

    This returns details of the previous transition after the specified instant. For example, if the instant represents a point where "summer" daylight saving time applies, then the method will return the transition from the previous "winter" time.

    Params:

    NameTypeAttributeDescription
    instant Instant

    the instant to get the previous transition after, not null, but null may be ignored if the rules have a single offset for all instants

    Return:

    ZoneOffsetTransition

    the previous transition after the specified instant, null if this is before the first transition

    public standardOffset(instant: Instant): ZoneOffset source

    Gets the standard offset for the specified instant in this zone.

    This provides access to historic information on how the standard offset has changed over time. The standard offset is the offset before any daylight saving time is applied. This is typically the offset applicable during winter.

    Needs tz data with standard offsets (field 7 of the packed format); throws for older data.

    Params:

    NameTypeAttributeDescription
    instant Instant

    the instant to find the offset information for, not null, but null may be ignored if the rules have a single offset for all instants

    Return:

    ZoneOffset

    the standard offset, not null

    Throw:

    Error

    if the tz data of the zone has no standard offsets

    public toString(): string source

    Return:

    string

    public transition(localDateTime: LocalDateTime): ZoneOffsetTransition source

    Gets the offset transition applicable at the specified local date-time in these rules.

    The mapping from a local date-time to an offset is not straightforward. There are three cases:

    • Normal, with one valid offset. For the vast majority of the year, the normal case applies, where there is a single valid offset for the local date-time.
    • Gap, with zero valid offsets. This is when clocks jump forward typically due to the spring daylight savings change from "winter" to "summer". In a gap there are local date-time values with no valid offset.
    • Overlap, with two valid offsets. This is when clocks are set back typically due to the autumn daylight savings change from "summer" to "winter". In an overlap there are local date-time values with two valid offsets.
    • A transition is used to model the cases of a Gap or Overlap. The Normal case will return null.

      There are various ways to handle the conversion from a {@code LocalDateTime}. One technique, using this method, would be:

       ZoneOffsetTransition trans = rules.getTransition(localDT);
       if (trans != null) {
         // Gap or Overlap: determine what to do from transition
       } else {
         // Normal case: only one valid offset
         zoneOffset = rule.getOffset(localDT);
       }
      

      Params:

      NameTypeAttributeDescription
      localDateTime LocalDateTime

      the local date-time to query for offset transition, not null, but null may be ignored if the rules have a single offset for all instants

      Return:

      ZoneOffsetTransition

      the offset transition, null if the local date-time is not in transition

      public transitionRules() source

      Not supported, always throws.

      In java.time, this returns the recurring rules (such as "last Sunday in March") for the years after the list of {@link #transitions()}. The tzdb data of this package is expanded into explicit transitions through the year 2499 and has no such rules. Use #nextTransition or #previousTransition to iterate over the transitions.

      Throw:

      Error

      always

      public transitions() source

      Not supported, always throws.

      In java.time, the complete set of transitions is this list of the historic transitions together with {@link #transitionRules()} for the later years. The tzdb data of this package contains only explicit transitions through the year 2499 and doesn't say where the historic part ends, so it can't return what java.time returns. Use #nextTransition or #previousTransition to iterate over the transitions.

      Throw:

      Error

      always

      public validOffsets(localDateTime: LocalDateTime): ZoneOffsetTransition | ZoneOffset[] source

      Gets the offset applicable at the specified local date-time in these rules.

      The mapping from a local date-time to an offset is not straightforward. There are three cases:

      • Normal, with one valid offset. For the vast majority of the year, the normal case applies, where there is a single valid offset for the local date-time.
      • Gap, with zero valid offsets. This is when clocks jump forward typically due to the spring daylight savings change from "winter" to "summer". In a gap there are local date-time values with no valid offset.
      • Overlap, with two valid offsets. This is when clocks are set back typically due to the autumn daylight savings change from "summer" to "winter". In an overlap there are local date-time values with two valid offsets.
      • Thus, for any given local date-time there can be zero, one or two valid offsets. This method returns that list of valid offsets, which is a list of size 0, 1 or 2. In the case where there are two offsets, the earlier offset is returned at index 0 and the later offset at index 1.

        There are various ways to handle the conversion from a {@code LocalDateTime}. One technique, using this method, would be:

         List<ZoneOffset> validOffsets = rules.getOffset(localDT);
         if (validOffsets.size() == 1) {
           // Normal case: only one valid offset
           zoneOffset = validOffsets.get(0);
         } else {
           // Gap or Overlap: determine what to do from transition (which will be non-null)
           ZoneOffsetTransition trans = rules.getTransition(localDT);
         }
        

        In theory, it is possible for there to be more than two valid offsets. This would happen if clocks to be put back more than once in quick succession. This has never happened in the history of time-zones and thus has no special handling. However, if it were to happen, then the list would return more than 2 entries.

        Params:

        NameTypeAttributeDescription
        localDateTime LocalDateTime

        the local date-time to query for valid offsets, not null may be ignored if the rules have a single offset for all instants

        Return:

        ZoneOffsetTransition | ZoneOffset[]

        the list of valid offsets, may be immutable, not null