isValidUtcOffset
Signature
Section titled “Signature”isValidUtcOffset(value: string): booleanReturn true when value is a UTC offset in the form the offset-instant pair stores: ISO 8601 extended ±HH:MM, optionally ±HH:MM:SS.
- This is the offset
toOffsetInstantreturns andfromOffsetInstanttakes, and the onegetTimeZoneOffsetandgetZonedOffsetreturn. - The
utcOffsetpattern is the whole check. Every string it matches is in range (hour00–23, minute and second00–59), so this validator is the pattern test plus the answer false for a non-string. Zis false: it is a designator meaning “this string is already UTC”, and for an event at UTC the pair’s offset is+00:00.- Seconds are allowed because some zones did not run on a whole minute:
Africa/Monroviawas-00:44:30until 1972. A fraction of a second is false. - Basic format (
-0400) and an hour alone (-04) are false. -00:00is true, and the functions that take an offset read it as+00:00.- A function whose result has no zone in it takes this offset in its time zone position too. A function that returns a zoned string, or formats with
Intl, takes a time zone identifier only: check that withisValidTimeZone, which accepts+0530and-08and rejects an offset with seconds.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | candidate UTC offset string |
Returns
Section titled “Returns”boolean indicating validity
Examples
Section titled “Examples”import { isValidUtcOffset } from "@northguild/gmt/instant/validate";
isValidUtcOffset("-04:00") // true