UNPKG

date-vir

Version:

Easy and explicit dates and times.

66 lines (65 loc) 2.23 kB
/** * A string that represents only date parts of a date. It's intended to be used like this: * year-month-day. * * @category Internal */ export type JustDateString = `${number}-${number}-${number}`; /** * A string that represents only time parts of a date, with seconds. It's intended to be used like * this: hour:minute:seconds. * * @category Internal */ export type JustTimeWithSecondsString = `${number}:${number}:${number}`; /** * A string that represents only time parts of a date, without seconds. It's intended to be used * like this: hour:minute. * * @category Internal */ export type JustTimeString = `${number}:${number}`; /** * A string that represents date and time parts of a date, with seconds. It's intended to be used * like this: year-month-dayThour:minute:seconds. * * @category Internal */ export type DateTimeWithSeconds = `${JustDateString}T${JustTimeWithSecondsString}`; /** * A string that represents date and time parts of a date, without seconds. It's intended to be used * like this: year-month-dayThour:minute. * * @category Internal */ export type DateTimeString = `${JustDateString}T${JustTimeString}`; /** * A full UTC ISO date time string: YYYY-MM-DDTHH:mm:ss.sssZ. * * @category ISO * @see * - https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date-time-string-format * - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_time_string_format */ export type UtcIsoString = `${JustDateString}T${JustTimeWithSecondsString}.${number}Z`; /** * A shape definition for {@link UtcIsoString}. * * @category ISO */ export declare const utcIsoStringShape: import("object-shape-tester").ShapeDefinition<import("object-shape-tester").CustomSpecifier<`${number}-${number}-${number}T${number}:${number}:${number}.${number}Z`>, false>; /** * Checks if the input is a valid UTC ISO string and type guards the input. * * @category ISO * @category Assertion * @example * * ```ts * import {isValidIsoString} from 'date-vir'; * * isValidIsoString('no'); // `false` * isValidIsoString('2024-05-01T20:18:17.123Z'); // `true` * ``` */ export declare function isValidIsoString(input: unknown): input is UtcIsoString;