ts-time-utils
Version:
A comprehensive TypeScript utility library for time, dates, durations, and calendar operations with full tree-shaking support
27 lines • 1.63 kB
TypeScript
/**
* Interval utilities: operations on time intervals [start, end)
*/
import type { Interval, DateInput } from './types.js';
/** Create an interval ensuring start <= end */
export declare function createInterval(start: DateInput, end: DateInput): Interval | null;
/** Validate an object is a proper interval */
export declare function isValidInterval(i: any): i is Interval;
/** Duration of interval in ms */
export declare function intervalDuration(i: Interval): number;
/** Whether interval contains date (inclusive start, exclusive end) */
export declare function intervalContains(i: Interval, date: DateInput): boolean;
/** Whether two intervals overlap */
export declare function intervalsOverlap(a: Interval, b: Interval): boolean;
/** Intersection of two intervals, or null */
export declare function intervalIntersection(a: Interval, b: Interval): Interval | null;
/** Merge overlapping or touching intervals into a minimal set */
export declare function mergeIntervals(intervals: Interval[]): Interval[];
/** Subtract interval b from a (can split into 0,1,2 intervals) */
export declare function subtractInterval(a: Interval, b: Interval): Interval[];
/** Split an interval into day-boundary intervals (UTC based) */
export declare function splitIntervalByDay(i: Interval): Interval[];
/** Total covered duration of possibly overlapping intervals */
export declare function totalIntervalCoverage(intervals: Interval[]): number;
/** Normalize array: filter invalid and merge */
export declare function normalizeIntervals(intervals: (Interval | null | undefined)[]): Interval[];
//# sourceMappingURL=interval.d.ts.map