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.

37 lines • 1.78 kB
/** * Return true when `dateTime` is between `start` and `end` (inclusive by default). * * - Uses Temporal.PlainDateTime.compare to compare date-times. * - Returns false if start > end (invalid range). * - Returns false if any input is invalid. * * @param dateTime ISO PlainDateTime string to check * @param start ISO PlainDateTime string for the start of the range * @param end ISO PlainDateTime string for the end of the range * @param options Whether each end of the range counts as inside it * @returns boolean indicating whether dateTime is between start and end * * @example isBetweenDateTime("2024-02-29T12:00:00", "2024-02-01T00:00:00", "2024-02-28T23:59:59") // false * @example isBetweenDateTime("2024-02-29T12:00:00", "2024-02-01T00:00:00", "2024-02-29T12:00:00") // true * @example isBetweenDateTime("2024-02-29T12:00:00", "2024-02-29T12:00:00", "2024-02-28T23:59:59") // false * @example isBetweenDateTime("2024-02-29T12:00:00", "2024-02-28T23:59:59", "2024-03-01T00:00:00") // true * @example isBetweenDateTime("invalid", "2024-02-01T00:00:00", "2024-02-28T23:59:59") // false * @example isBetweenDateTime("2024-02-29T12:00:00", "invalid", "2024-02-28T23:59:59") // false * @example isBetweenDateTime("2024-02-29T12:00:00", "2024-02-01T00:00:00", "invalid") // false */ export declare function isBetweenDateTime(dateTime: string, start: string, end: string, options?: { /** * Whether `dateTime` equal to `start` counts as inside the range. `false` requires it to * be after `start`. * * @defaultValue `true` */ inclusiveStart?: boolean; /** * Whether `dateTime` equal to `end` counts as inside the range. `false` requires it to be * before `end`. * * @defaultValue `true` */ inclusiveEnd?: boolean; }): boolean;