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

ZoneIdFactory

See:

  • ZoneId Helper class to avoid dependency cycles. Static methods of the class ZoneIdFactory are added automatically to class ZoneId.

Static Method Summary

Static Public Methods
public static

Obtains an instance of {@code ZoneId} from a temporal object.

public static

of(zoneId: string): ZoneId

Obtains an instance of {@code ZoneId} from an ID ensuring that the ID is valid and available for use.

public static

ofOffset(prefix: string, offset: ZoneOffset): ZoneId

Obtains an instance of {@code ZoneId} wrapping an offset.

public static

Gets the system default time-zone.

Static Public Methods

public static from(temporal: TemporalAccessor): ZoneId source

Obtains an instance of {@code ZoneId} from a temporal object.

A {@code TemporalAccessor} represents some form of date and time information. This factory converts the arbitrary temporal object to an instance of {@code ZoneId}.

The conversion will try to obtain the zone in a way that favours region-based zones over offset-based zones using {@link TemporalQueries#zone()}.

This method matches the signature of the functional interface TemporalQuery allowing it to be used in queries via method reference, {@code ZoneId::from}.

Params:

NameTypeAttributeDescription
temporal TemporalAccessor
  • nullable: false

the temporal object to convert, not null

Return:

ZoneId

the zone ID, not null

Throw:

*

DateTimeException if unable to convert to a {@code ZoneId}

public static of(zoneId: string): ZoneId source

Obtains an instance of {@code ZoneId} from an ID ensuring that the ID is valid and available for use.

This method parses the ID producing a {@code ZoneId} or {@code ZoneOffset}. A {@code ZoneOffset} is returned if the ID is 'Z', or starts with '+' or '-'. The result will always be a valid ID for which ZoneRules can be obtained.

Parsing matches the zone ID step by step as follows.

  • If the zone ID equals 'Z', the result is {@code ZoneOffset.UTC}.
  • If the zone ID consists of a single letter, the zone ID is invalid and {@code DateTimeException} is thrown.
  • If the zone ID starts with '+' or '-', the ID is parsed as a {@code ZoneOffset} using {@link ZoneOffset#of(String)}.
  • If the zone ID equals 'GMT', 'UTC' or 'UT' then the result is a {@code ZoneId} with the same ID and rules equivalent to {@code ZoneOffset.UTC}.
  • If the zone ID starts with 'UTC+', 'UTC-', 'GMT+', 'GMT-', 'UT+' or 'UT-' then the ID is a prefixed offset-based ID. The ID is split in two, with a two or three letter prefix and a suffix starting with the sign. The suffix is parsed as a {@link ZoneOffset#of(String) ZoneOffset}. The result will be a {@code ZoneId} with the specified UTC/GMT/UT prefix and the normalized offset ID as per {@link ZoneOffset#getId()}. The rules of the returned {@code ZoneId} will be equivalent to the parsed {@code ZoneOffset}.
  • All other IDs are parsed as region-based zone IDs. Region IDs must match the regular expression [A-Za-z][A-Za-z0-9~/._+-]+ otherwise a {@code DateTimeException} is thrown. If the zone ID is not in the configured set of IDs, {@code ZoneRulesException} is thrown. The detailed format of the region ID depends on the group supplying the data. The default set of data is supplied by the IANA Time Zone Database (TZDB). This has region IDs of the form '{area}/{city}', such as 'Europe/Paris' or 'America/New_York'. This is compatible with most IDs from java.util.TimeZone.

Params:

NameTypeAttributeDescription
zoneId string

the time-zone ID, not null

Return:

ZoneId

the zone ID, not null

Throw:

*

DateTimeException if the zone ID has an invalid format

*

ZoneRulesException if the zone ID is a region ID that cannot be found

public static ofOffset(prefix: string, offset: ZoneOffset): ZoneId source

Obtains an instance of {@code ZoneId} wrapping an offset.

If the prefix is 'GMT', 'UTC', or 'UT' a {@code ZoneId} with the prefix and the non-zero offset is returned. If the prefix is empty {@code ''} the {@code ZoneOffset} is returned.

Params:

NameTypeAttributeDescription
prefix string

the time-zone ID, not null

offset ZoneOffset

the offset, not null

Return:

ZoneId

the zone ID, not null

Throw:

*

IllegalArgumentException if the prefix is not one of 'GMT', 'UTC', or 'UT', or ''

public static systemDefault(): ZoneId source

Gets the system default time-zone.

Return:

ZoneId

the zone ID, not null