UNPKG

@northguild/gmt

Version:

Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.

32 lines • 2.33 kB
/** * RegExp matching the shape of a time zone identifier: Temporal's `TimeZoneIdentifier` grammar * (§13.31, the ISO 8601 / RFC 9557 grammar), * `TimeZoneIdentifier ::: UTCOffset[~SubMinutePrecision] | TimeZoneIANAName`. * * - An offset identifier (`UTCOffset[~SubMinutePrecision]`): an ASCII sign and a two-digit hour * `00`–`23`, optionally followed by two minute digits `00`–`59`, with or without `:` (`+05`, * `+0530`, `-08:00`). No seconds and no fraction. `Intl.DateTimeFormat` accepts the same * offsets (ECMA-262 `IsTimeZoneOffsetString`, which ECMA-402 calls). * - An IANA name (`TimeZoneIANAName`): one or more `/`-separated components. Each starts with a * letter, `.` or `_` (`TZLeadingChar`) and continues with letters, digits, `.`, `_`, `-` or `+` * (`TZChar`). So single-component names match (`UTC`, `Japan`, `Zulu`, `EST5EDT`, `GMT+0`, * `NZ-CHAT`), as do `Area/Location` names at any depth (`America/Argentina/Buenos_Aires`, * `Etc/GMT+5`). Temporal must accept every Zone and Link name in the IANA database, and tzdb's * `backward` file has more than forty slash-less ones. * - Letter case is not checked: ECMA-402 matches an identifier ASCII-case-insensitively, so `utc` * and `asia/kolkata` name the same zones as `UTC` and `Asia/Kolkata`. * - SHAPE ONLY. Whether the name exists is decided by Temporal: its only consumer, * `isValidTimeZone`, also requires `Temporal.ZonedDateTime.from` to accept the zone. * * @example timeZoneLike.test("UTC") // true * @example timeZoneLike.test("Asia/Kolkata") // true * @example timeZoneLike.test("Japan") // true (single-component IANA link) * @example timeZoneLike.test("Etc/GMT+5") // true * @example timeZoneLike.test("Custom/Zone") // true (shape only; existence is not checked) * @example timeZoneLike.test("+05:00") // true (an offset identifier) * @example timeZoneLike.test("-0800") // true (a basic-format offset identifier) * @example timeZoneLike.test("+05:00:00") // false (no seconds in an offset identifier) * @example timeZoneLike.test("-foo/bar") // false (a name cannot start with - or +) * @example timeZoneLike.test("UTC+05:00") // false (":" is not a name character) */ export declare const timeZoneLike: RegExp;