UNPKG

2.08 kBTypeScriptView Raw
1import type { ContextOptions, Interval, StepOptions } from "./types.js";
2/**
3 * The {@link eachQuarterOfInterval} function options.
4 */
5export interface EachQuarterOfIntervalOptions<DateType extends Date = Date>
6 extends StepOptions,
7 ContextOptions<DateType> {}
8/**
9 * The {@link eachQuarterOfInterval} 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 EachQuarterOfIntervalResult<
15 IntervalType extends Interval,
16 Options extends EachQuarterOfIntervalOptions | undefined,
17> = Array<
18 Options extends EachQuarterOfIntervalOptions<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 eachQuarterOfInterval
28 * @category Interval Helpers
29 * @summary Return the array of quarters within the specified time interval.
30 *
31 * @description
32 * Return the array of quarters 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 quarters from the quarter of the interval start to the quarter of the interval end
41 *
42 * @example
43 * // Each quarter within interval 6 February 2014 - 10 August 2014:
44 * const result = eachQuarterOfInterval({
45 * start: new Date(2014, 1, 6),
46 * end: new Date(2014, 7, 10),
47 * })
48 * //=> [
49 * // Wed Jan 01 2014 00:00:00,
50 * // Tue Apr 01 2014 00:00:00,
51 * // Tue Jul 01 2014 00:00:00,
52 * // ]
53 */
54export declare function eachQuarterOfInterval<
55 IntervalType extends Interval,
56 Options extends EachQuarterOfIntervalOptions | undefined = undefined,
57>(
58 interval: IntervalType,
59 options?: Options,
60): EachQuarterOfIntervalResult<IntervalType, Options>;