UNPKG

1 kBTypeScriptView Raw
1import type { Day } from "./types.js";
2/**
3 * @name previousDay
4 * @category Weekday Helpers
5 * @summary When is the previous day of the week?
6 *
7 * @description
8 * When is the previous day of the week? 0-6 the day of the week, 0 represents Sunday.
9 *
10 * @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).
11 *
12 * @param date - The date to check
13 * @param day - The day of the week
14 *
15 * @returns The date is the previous day of week
16 *
17 * @example
18 * // When is the previous Monday before Mar, 20, 2020?
19 * const result = previousDay(new Date(2020, 2, 20), 1)
20 * //=> Mon Mar 16 2020 00:00:00
21 *
22 * @example
23 * // When is the previous Tuesday before Mar, 21, 2020?
24 * const result = previousDay(new Date(2020, 2, 21), 2)
25 * //=> Tue Mar 17 2020 00:00:00
26 */
27export declare function previousDay<DateType extends Date>(
28 date: DateType | number | string,
29 day: Day,
30): DateType;