UNPKG

2.07 kBTypeScriptView Raw
1import type { ContextOptions, Interval, StepOptions } from "./types.js";
2/**
3 * The {@link eachDayOfInterval} function options.
4 */
5export interface EachDayOfIntervalOptions<DateType extends Date = Date>
6 extends StepOptions,
7 ContextOptions<DateType> {}
8/**
9 * The {@link eachDayOfInterval} function result type. It resolves the proper data type.
10 * It uses the first argument date object type, starting from the date argument,
11 * then the start interval date, and finally the end interval date. If
12 * a context function is passed, it uses the context function return type.
13 */
14export type EachDayOfIntervalResult<
15 IntervalType extends Interval,
16 Options extends EachDayOfIntervalOptions | undefined,
17> = Array<
18 Options extends EachDayOfIntervalOptions<infer DateType>
19 ? DateType
20 : IntervalType["start"] extends Date
21 ? IntervalType["start"]
22 : IntervalType["end"] extends Date
23 ? IntervalType["end"]
24 : Date
25>;
26/**
27 * @name eachDayOfInterval
28 * @category Interval Helpers
29 * @summary Return the array of dates within the specified time interval.
30 *
31 * @description
32 * Return the array of dates within the specified time interval.
33 *
34 * @typeParam IntervalType - Interval type.
35 * @typeParam Options - Options type.
36 *
37 * @param interval - The interval.
38 * @param options - An object with options.
39 *
40 * @returns The array with starts of days from the day of the interval start to the day of the interval end
41 *
42 * @example
43 * // Each day between 6 October 2014 and 10 October 2014:
44 * const result = eachDayOfInterval({
45 * start: new Date(2014, 9, 6),
46 * end: new Date(2014, 9, 10)
47 * })
48 * //=> [
49 * // Mon Oct 06 2014 00:00:00,
50 * // Tue Oct 07 2014 00:00:00,
51 * // Wed Oct 08 2014 00:00:00,
52 * // Thu Oct 09 2014 00:00:00,
53 * // Fri Oct 10 2014 00:00:00
54 * // ]
55 */
56export declare function eachDayOfInterval<
57 IntervalType extends Interval,
58 Options extends EachDayOfIntervalOptions | undefined = undefined,
59>(
60 interval: IntervalType,
61 options?: Options,
62): EachDayOfIntervalResult<IntervalType, Options>;