UNPKG

1.25 kBTypeScriptView Raw
1import type { LocalizedOptions, WeekOptions } from "./types.js";
2/**
3 * The {@link setDay} function options.
4 */
5export interface SetDayOptions
6 extends LocalizedOptions<"options">,
7 WeekOptions {}
8/**
9 * @name setDay
10 * @category Weekday Helpers
11 * @summary Set the day of the week to the given date.
12 *
13 * @description
14 * Set the day of the week to the given date.
15 *
16 * @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).
17 *
18 * @param date - The date to be changed
19 * @param day - The day of the week of the new date
20 * @param options - An object with options.
21 *
22 * @returns The new date with the day of the week set
23 *
24 * @example
25 * // Set week day to Sunday, with the default weekStartsOn of Sunday:
26 * const result = setDay(new Date(2014, 8, 1), 0)
27 * //=> Sun Aug 31 2014 00:00:00
28 *
29 * @example
30 * // Set week day to Sunday, with a weekStartsOn of Monday:
31 * const result = setDay(new Date(2014, 8, 1), 0, { weekStartsOn: 1 })
32 * //=> Sun Sep 07 2014 00:00:00
33 */
34export declare function setDay<DateType extends Date>(
35 date: DateType | number | string,
36 day: number,
37 options?: SetDayOptions,
38): DateType;