UNPKG

2.11 kBTypeScriptView Raw
1import type { ContextOptions, Interval, StepOptions } from "./types.js";
2/**
3 * The {@link eachMinuteOfInterval} function options.
4 */
5export interface EachMinuteOfIntervalOptions<DateType extends Date = Date>
6 extends StepOptions,
7 ContextOptions<DateType> {}
8/**
9 * The {@link eachMinuteOfInterval} 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 EachMinuteOfIntervalResult<
15 IntervalType extends Interval,
16 Options extends EachMinuteOfIntervalOptions | undefined,
17> = Array<
18 Options extends EachMinuteOfIntervalOptions<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 eachMinuteOfInterval
28 * @category Interval Helpers
29 * @summary Return the array of minutes within the specified time interval.
30 *
31 * @description
32 * Returns the array of minutes 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 minutes from the minute of the interval start to the minute of the interval end
41 *
42 * @example
43 * // Each minute between 14 October 2020, 13:00 and 14 October 2020, 13:03
44 * const result = eachMinuteOfInterval({
45 * start: new Date(2014, 9, 14, 13),
46 * end: new Date(2014, 9, 14, 13, 3)
47 * })
48 * //=> [
49 * // Wed Oct 14 2014 13:00:00,
50 * // Wed Oct 14 2014 13:01:00,
51 * // Wed Oct 14 2014 13:02:00,
52 * // Wed Oct 14 2014 13:03:00
53 * // ]
54 */
55export declare function eachMinuteOfInterval<
56 IntervalType extends Interval,
57 Options extends EachMinuteOfIntervalOptions | undefined = undefined,
58>(
59 interval: IntervalType,
60 options?: Options,
61): EachMinuteOfIntervalResult<IntervalType, Options>;