@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.
26 lines • 1.52 kB
TypeScript
/**
* Return true when the input is a valid PlainDate or PlainDateTime ISO string.
*
* - Accepts both PlainDate ("2024-02-29") and PlainDateTime ("2024-02-29T12:34:56") formats.
* - The whole string must match `plainDate` or `plainDateTime`.
* - Accepts no annotation of any kind: a time zone, a calendar (`[u-ca=iso8601]`) or an
* elective one (`[foo=bar]`) returns `false`.
* - Rejects leap seconds and invalid dates/times.
* - 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 PlainDate or PlainDateTime
* @returns boolean indicating validity
*
* @example isValidIsoDateLike("2024-02-29") // true
* @example isValidIsoDateLike("2024-02-30") // false (invalid date)
* @example isValidIsoDateLike("2024-02-29T12:34:56") // true
* @example isValidIsoDateLike("2024-02-29T24:00:00") // false (invalid time)
* @example isValidIsoDateLike("2024-12-31T23:59:60") // false (leap second)
* @example isValidIsoDateLike("2024-02-29[u-ca=iso8601]") // false (no annotation of any kind)
* @example isValidIsoDateLike("2024-02-29[u-ca=hebrew]") // false (no annotation of any kind)
* @example isValidIsoDateLike(null) // false
*/
export declare function isValidIsoDateLike(value: string): boolean;
export declare function isValidIsoDateLike(value: {} | null | undefined | void): boolean;
export declare function isValidIsoDateLike(value: unknown): value is string;