@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.
31 lines • 1.96 kB
TypeScript
/**
* Return true when the provided string is a valid ISO 8601 UTC datetime.
*
* - The whole string must match `utcDateTime` (`<date>T<time>Z`): ISO 8601
* extended format with an upper-case `Z`, so `z`, a `t` or space separator and basic format fail.
* - Accepts no annotation of any kind: a time zone, a calendar or an elective one returns `false`.
* - 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 `±YYYYYY` year and RFC 9557 annotations.
* For the plain RFC 3339 spelling that readers other than Temporal expect, use
* `isValidUtcTimestamp`, 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.
* - A value that is not a string, a `String` object included, returns `false`. A `true` result
* narrows an `unknown` value to `string`.
*
* @param value any value; a string is checked as an ISO 8601 UTC datetime
* @returns boolean indicating whether the input is a valid UTC datetime
*
* @example isValidUtc("2024-03-17T14:30:45Z") // true
* @example isValidUtc("2024-01-01Z") // false — date-only not supported
* @example isValidUtc("2024-03-17T14:30:45z") // false — lower-case z (ISO 8601 extended format only)
* @example isValidUtc("2024-03-17T14:30:45Z[Europe/Paris]") // false — no annotation of any kind
* @example isValidUtc("2024-03-17T14:30:45Z[!foo=bar]") // false — unknown critical annotation
* @example isValidUtc("2024-12-31T23:59:60Z") // false
* @example isValidUtc("invalid") // false
* @example isValidUtc(null) // false
*/
export declare function isValidUtc(value: string): boolean;
export declare function isValidUtc(value: {} | null | undefined | void): boolean;
export declare function isValidUtc(value: unknown): value is string;