UNPKG

1.87 kBTypeScriptView Raw
1import type { ContextOptions, Interval, StepOptions } from "./types.js";
2/**
3 * The {@link eachHourOfInterval} function options.
4 */
5export interface EachHourOfIntervalOptions<DateType extends Date = Date>
6 extends StepOptions,
7 ContextOptions<DateType> {}
8/**
9 * The {@link eachHourOfInterval} function result type.
10 * Resolves to the appropriate date type based on inputs.
11 */
12export type EachHourOfIntervalResult<
13 IntervalType extends Interval,
14 Options extends EachHourOfIntervalOptions | undefined,
15> = Array<
16 Options extends EachHourOfIntervalOptions<infer DateType>
17 ? DateType
18 : IntervalType["start"] extends Date
19 ? IntervalType["start"]
20 : IntervalType["end"] extends Date
21 ? IntervalType["end"]
22 : Date
23>;
24/**
25 * @name eachHourOfInterval
26 * @category Interval Helpers
27 * @summary Return the array of hours within the specified time interval.
28 *
29 * @description
30 * Return the array of hours within the specified time interval.
31 *
32 * @typeParam IntervalType - Interval type.
33 * @typeParam Options - Options type.
34 *
35 * @param interval - The interval.
36 * @param options - An object with options.
37 *
38 * @returns The array with starts of hours from the hour of the interval start to the hour of the interval end
39 *
40 * @example
41 * // Each hour between 6 October 2014, 12:00 and 6 October 2014, 15:00
42 * const result = eachHourOfInterval({
43 * start: new Date(2014, 9, 6, 12),
44 * end: new Date(2014, 9, 6, 15)
45 * });
46 * //=> [
47 * // Mon Oct 06 2014 12:00:00,
48 * // Mon Oct 06 2014 13:00:00,
49 * // Mon Oct 06 2014 14:00:00,
50 * // Mon Oct 06 2014 15:00:00
51 * // ]
52 */
53export declare function eachHourOfInterval<
54 IntervalType extends Interval,
55 Options extends EachHourOfIntervalOptions | undefined = undefined,
56>(
57 interval: IntervalType,
58 options?: Options,
59): EachHourOfIntervalResult<IntervalType, Options>;