@burglekitt/gmt
Version:
Temporal-based date and time utilities with timezone support and polyfill integration
29 lines (28 loc) • 1.45 kB
TypeScript
/**
* Return true when `time` is between `start` and `end` (inclusive by default).
*
* - Uses Temporal.PlainTime.compare to compare times.
* - Returns false if start > end (invalid range).
* - Returns false if any input is invalid.
* - Use options.inclusiveStart and options.inclusiveEnd to control boundary inclusivity.
* - Note: PlainTime comparison does not account for day overflow.
*
* @param time ISO PlainTime string to check
* @param start ISO PlainTime string for the start of the range
* @param end ISO PlainTime string for the end of the range
* @param options { inclusiveStart?: boolean = true, inclusiveEnd?: boolean = true }
* @returns boolean indicating whether time is between start and end
*
* @example isBetweenTime("12:34:56", "12:00:00", "13:00:00") // true
* @example isBetweenTime("12:34:56", "12:34:56", "13:00:00") // true
* @example isBetweenTime("12:34:56", "12:34:57", "13:00:00") // false
* @example isBetweenTime("12:34:56", "12:00:00", "12:34:56") // true
* @example isBetweenTime("12:34:56", "12:00:00", "12:34:55") // false
* @example isBetweenTime("invalid", "12:00:00", "13:00:00") // false
* @example isBetweenTime("12:34:56", "invalid", "13:00:00") // false
* @example isBetweenTime("12:34:56", "12:00:00", "invalid") // false
*/
export declare function isBetweenTime(time: string, start: string, end: string, options?: {
inclusiveStart?: boolean;
inclusiveEnd?: boolean;
}): boolean;