UNPKG

1.94 kBTypeScriptView Raw
1import type { ContextOptions, Interval, StepOptions } from "./types.js";
2/**
3 * The {@link eachMonthOfInterval} function options.
4 */
5export interface EachMonthOfIntervalOptions<DateType extends Date = Date>
6 extends StepOptions,
7 ContextOptions<DateType> {}
8/**
9 * The {@link eachMonthOfInterval} function result type. It resolves the proper data type.
10 */
11export type EachMonthOfIntervalResult<
12 IntervalType extends Interval,
13 Options extends EachMonthOfIntervalOptions | undefined,
14> = Array<
15 Options extends EachMonthOfIntervalOptions<infer DateType>
16 ? DateType
17 : IntervalType["start"] extends Date
18 ? IntervalType["start"]
19 : IntervalType["end"] extends Date
20 ? IntervalType["end"]
21 : Date
22>;
23/**
24 * @name eachMonthOfInterval
25 * @category Interval Helpers
26 * @summary Return the array of months within the specified time interval.
27 *
28 * @description
29 * Return the array of months within the specified time interval.
30 *
31 * @typeParam IntervalType - Interval type.
32 * @typeParam Options - Options type.
33 *
34 * @param interval - The interval.
35 * @param options - An object with options.
36 *
37 * @returns The array with starts of months from the month of the interval start to the month of the interval end
38 *
39 * @example
40 * // Each month between 6 February 2014 and 10 August 2014:
41 * const result = eachMonthOfInterval({
42 * start: new Date(2014, 1, 6),
43 * end: new Date(2014, 7, 10)
44 * })
45 * //=> [
46 * // Sat Feb 01 2014 00:00:00,
47 * // Sat Mar 01 2014 00:00:00,
48 * // Tue Apr 01 2014 00:00:00,
49 * // Thu May 01 2014 00:00:00,
50 * // Sun Jun 01 2014 00:00:00,
51 * // Tue Jul 01 2014 00:00:00,
52 * // Fri Aug 01 2014 00:00:00
53 * // ]
54 */
55export declare function eachMonthOfInterval<
56 IntervalType extends Interval,
57 Options extends EachMonthOfIntervalOptions | undefined = undefined,
58>(
59 interval: IntervalType,
60 options?: Options,
61): EachMonthOfIntervalResult<IntervalType, Options>;