Home Reference Source Repository
import {ZoneRules} from 'js-joda/src/zone/ZoneRules.js'
public class | source

ZoneRules

Direct Subclass:

src/zone/ZoneRules.js~Fixed, SystemDefaultZoneRules

Static Method Summary

Static Public Methods
public static

of(offset: ZoneOffset): ZoneRules

Obtains an instance of {@code ZoneRules} that always uses the same offset.

Method Summary

Public Methods
public

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

offset(instantOrLocalDateTime: *): ZoneOffset

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.

Static Public Methods

public static of(offset: ZoneOffset): ZoneRules source

Obtains an instance of {@code ZoneRules} that always uses the same offset.

The returned rules always have the same offset.

Params:

NameTypeAttributeDescription
offset ZoneOffset

the offset, not null

Return:

ZoneRules

the zone rules, not null

Public Methods

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 offset(instantOrLocalDateTime: *): ZoneOffset source

Params:

NameTypeAttributeDescription
instantOrLocalDateTime *

Return:

ZoneOffset

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