UNPKG

@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.

29 lines • 1.63 kB
/** * Return true if `value` is a valid ISO PlainDate string. * * - The part before the first annotation must match `plainDate` (a date, not a date-time). * - Reads RFC 9557 annotations as `Temporal.PlainDate.from` does: elective ones (`[foo=bar]`) * and a time zone annotation are ignored, and an unknown critical one (`[!foo=bar]`) is * rejected. The calendar must be ISO (`[u-ca=iso8601]` is accepted); a non-ISO calendar is * `isValidCalendarDate`'s input. * - Rejects leap seconds (e.g., "2024-12-31T23:59:60"). * - Rejects invalid dates (e.g., "2024-02-30"). * - 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 * @returns boolean indicating validity * * @example isValidDate("2024-03-10") // true * @example isValidDate("2024-02-30") // false * @example isValidDate("2024-03-10[u-ca=iso8601]") // true * @example isValidDate("2024-03-10[foo=bar]") // true (elective annotation ignored) * @example isValidDate("2024-03-10[!foo=bar]") // false (unknown critical annotation) * @example isValidDate("2024-03-10[u-ca=hebrew]") // false (use isValidCalendarDate) * @example isValidDate("invalid") // false * @example isValidDate("2024-12-31T23:59:60") // false (leap second - not a valid date) * @example isValidDate(null) // false */ export declare function isValidDate(value: string): boolean; export declare function isValidDate(value: {} | null | undefined | void): boolean; export declare function isValidDate(value: unknown): value is string;