Skip to content

timeZoneLike

const timeZoneLike: RegExp = /^(?:[+-](?:[01][0-9]|2[0-3])(?::?[0-5][0-9])?|[A-Za-z._][A-Za-z0-9._+-]*(?:\/[A-Za-z._][A-Za-z0-9._+-]*)*)$/;

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.

import { timeZoneLike } from "@northguild/gmt";
timeZoneLike.test("UTC") // true
timeZoneLike.test("America/New_York") // true
timeZoneLike.test("Japan") // true (single-component IANA link)
timeZoneLike.test("Etc/GMT+5") // true
timeZoneLike.test("Custom/Zone") // true (shape only; existence is not checked)
timeZoneLike.test("+05:00") // true (an offset identifier)
timeZoneLike.test("-0800") // true (a basic-format offset identifier)
timeZoneLike.test("+05:00:00") // false (no seconds in an offset identifier)
timeZoneLike.test("-foo/bar") // false (a name cannot start with - or +)
timeZoneLike.test("UTC+05:00") // false (":" is not a name character)

regex/time-zone-like.ts