UNPKG

2.08 kBTypeScriptView Raw
1import type { Interval } from "./types.js";
2/**
3 * The {@link areIntervalsOverlapping} function options.
4 */
5export interface AreIntervalsOverlappingOptions {
6 /** Whether the comparison is inclusive or not */
7 inclusive?: boolean;
8}
9/**
10 * @name areIntervalsOverlapping
11 * @category Interval Helpers
12 * @summary Is the given time interval overlapping with another time interval?
13 *
14 * @description
15 * Is the given time interval overlapping with another time interval? Adjacent intervals do not count as overlapping unless `inclusive` is set to `true`.
16 *
17 * @param intervalLeft - The first interval to compare.
18 * @param intervalRight - The second interval to compare.
19 * @param options - The object with options
20 *
21 * @returns Whether the time intervals are overlapping
22 *
23 * @example
24 * // For overlapping time intervals:
25 * areIntervalsOverlapping(
26 * { start: new Date(2014, 0, 10), end: new Date(2014, 0, 20) },
27 * { start: new Date(2014, 0, 17), end: new Date(2014, 0, 21) }
28 * )
29 * //=> true
30 *
31 * @example
32 * // For non-overlapping time intervals:
33 * areIntervalsOverlapping(
34 * { start: new Date(2014, 0, 10), end: new Date(2014, 0, 20) },
35 * { start: new Date(2014, 0, 21), end: new Date(2014, 0, 22) }
36 * )
37 * //=> false
38 *
39 * @example
40 * // For adjacent time intervals:
41 * areIntervalsOverlapping(
42 * { start: new Date(2014, 0, 10), end: new Date(2014, 0, 20) },
43 * { start: new Date(2014, 0, 20), end: new Date(2014, 0, 30) }
44 * )
45 * //=> false
46 *
47 * @example
48 * // Using the inclusive option:
49 * areIntervalsOverlapping(
50 * { start: new Date(2014, 0, 10), end: new Date(2014, 0, 20) },
51 * { start: new Date(2014, 0, 20), end: new Date(2014, 0, 24) }
52 * )
53 * //=> false
54 *
55 * @example
56 * areIntervalsOverlapping(
57 * { start: new Date(2014, 0, 10), end: new Date(2014, 0, 20) },
58 * { start: new Date(2014, 0, 20), end: new Date(2014, 0, 24) },
59 * { inclusive: true }
60 * )
61 * //=> true
62 */
63export declare function areIntervalsOverlapping(
64 intervalLeft: Interval,
65 intervalRight: Interval,
66 options?: AreIntervalsOverlappingOptions,
67): boolean;