@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.
23 lines • 1.35 kB
TypeScript
/**
* Return true if `start` and `end` form a valid time interval — both parseable as
* ISO PlainTime strings and `start <= end`.
*
* - Both inputs must be ISO 8601 time strings (e.g. `"14:30:00"`).
* - Equal `start === end` is valid.
* - Invalid input, malformed strings, or leap-second strings return `false`.
* - Each endpoint must satisfy `isValidTime`, so annotations are read as Temporal reads them: a time
* zone annotation (`[Europe/Paris]`), `[u-ca=iso8601]` and an elective annotation (`[foo=bar]`) are
* ignored; an unknown critical annotation (`[!foo=bar]`) is rejected.
*
* @param start ISO 8601 time string (interval start)
* @param end ISO 8601 time string (interval end)
* @returns true if start and end form a valid time interval, or false on invalid input
*
* @example isValidTimeInterval("09:00:00", "17:00:00") // true
* @example isValidTimeInterval("12:00:00", "12:00:00") // true
* @example isValidTimeInterval("17:00:00", "09:00:00") // false
* @example isValidTimeInterval("invalid", "12:00:00") // false
* @example isValidTimeInterval("09:00:00[u-ca=iso8601]", "17:00:00[foo=bar]") // true (annotations ignored)
* @example isValidTimeInterval("09:00:00[!foo=bar]", "17:00:00") // false (unknown critical annotation)
*/
export declare function isValidTimeInterval(start: string, end: string): boolean;