1 | import type { NormalizedInterval } from "./types.js";
|
2 | /**
|
3 | * The {@link interval} function options.
|
4 | */
|
5 | export interface IntervalOptions {
|
6 | /** Asserts that the interval is positive (start is after the end). */
|
7 | assertPositive?: boolean;
|
8 | }
|
9 | /**
|
10 | * @name interval
|
11 | * @category Interval Helpers
|
12 | * @summary Creates an interval object and validates its values.
|
13 | *
|
14 | * @description
|
15 | * Creates a normalized interval object and validates its values. If the interval is invalid, an exception is thrown.
|
16 | *
|
17 | * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
|
18 | *
|
19 | * @param start - The start of the interval.
|
20 | * @param end - The end of the interval.
|
21 | * @param options - The options object.
|
22 | *
|
23 | * @throws `Start date is invalid` when `start` is invalid.
|
24 | * @throws `End date is invalid` when `end` is invalid.
|
25 | * @throws `End date must be after start date` when end is before `start` and `options.assertPositive` is true.
|
26 | *
|
27 | * @returns The normalized and validated interval object.
|
28 | */
|
29 | export declare function interval<DateType extends Date>(
|
30 | start: DateType | number | string,
|
31 | end: DateType | number | string,
|
32 | options?: IntervalOptions,
|
33 | ): NormalizedInterval<DateType>;
|