UNPKG

1.37 kBTypeScriptView Raw
1import type { ContextOptions, DateArg, Day } from "./types.js";
2/**
3 * The {@link nextDay} function options.
4 */
5export interface NextDayOptions<DateType extends Date = Date>
6 extends ContextOptions<DateType> {}
7/**
8 * @name nextDay
9 * @category Weekday Helpers
10 * @summary When is the next day of the week? 0-6 the day of the week, 0 represents Sunday.
11 *
12 * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
13 * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
14 *
15 * @param date - The date to check
16 * @param day - Day of the week
17 * @param options - An object with options
18 *
19 * @returns The date is the next day of the week
20 *
21 * @example
22 * // When is the next Monday after Mar, 20, 2020?
23 * const result = nextDay(new Date(2020, 2, 20), 1)
24 * //=> Mon Mar 23 2020 00:00:00
25 *
26 * @example
27 * // When is the next Tuesday after Mar, 21, 2020?
28 * const result = nextDay(new Date(2020, 2, 21), 2)
29 * //=> Tue Mar 24 2020 00:00:00
30 */
31export declare function nextDay<
32 DateType extends Date,
33 ResultDate extends Date = DateType,
34>(
35 date: DateArg<DateType>,
36 day: Day,
37 options?: NextDayOptions<ResultDate> | undefined,
38): ResultDate;