isValidUtc
Signature
Section titled “Signature”isValidUtc(value: string): booleanReturn true when the provided string is a valid ISO 8601 UTC datetime.
- The part before the first annotation must match
utcDateTime(<date>T<time>Z): ISO 8601 extended format with an upper-caseZ, soz, ator space separator and basic format fail. - Reads RFC 9557 annotations as
Temporal.Instant.fromdoes: elective ones ([foo=bar]), a time zone annotation and a calendar annotation are ignored (an instant has neither), and an unknown critical one ([!foo=bar]) is rejected. - Accepts four forms beyond the timestamp shape
YYYY-MM-DDTHH:MM:SS[.f]Z: a time without seconds, a comma before the fraction, an expanded±YYYYYYyear and RFC 9557 annotations. For the plain RFC 3339 spelling that readers other than Temporal expect, useisValidUtcTimestamp, which is false for all four. - Rejects leap seconds (e.g., “2024-12-31T23:59:60Z”).
- Uses Temporal.Instant.from for validation.
- Requires a time component — date-only strings (“2024-01-01Z”) are rejected.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | input UTC datetime string (ISO 8601) |
Returns
Section titled “Returns”boolean indicating whether the input is a valid UTC datetime
Examples
Section titled “Examples”import { isValidUtc } from "@northguild/gmt/utc/validate";
isValidUtc("2024-03-17T14:30:45Z") // true