1 | import type {
|
2 | FirstWeekContainsDateOptions,
|
3 | LocalizedOptions,
|
4 | WeekOptions,
|
5 | } from "./types.js";
|
6 | /**
|
7 | * The {@link setWeek} function options.
|
8 | */
|
9 | export interface SetWeekOptions
|
10 | extends LocalizedOptions<"options">,
|
11 | WeekOptions,
|
12 | FirstWeekContainsDateOptions {}
|
13 | /**
|
14 | * @name setWeek
|
15 | * @category Week Helpers
|
16 | * @summary Set the local week to the given date.
|
17 | *
|
18 | * @description
|
19 | * Set the local week to the given date, saving the weekday number.
|
20 | * The exact calculation depends on the values of
|
21 | * `options.weekStartsOn` (which is the index of the first day of the week)
|
22 | * and `options.firstWeekContainsDate` (which is the day of January, which is always in
|
23 | * the first week of the week-numbering year)
|
24 | *
|
25 | * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system
|
26 | *
|
27 | * @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).
|
28 | *
|
29 | * @param date - The date to be changed
|
30 | * @param week - The week of the new date
|
31 | * @param options - An object with options
|
32 | *
|
33 | * @returns The new date with the local week set
|
34 | *
|
35 | * @example
|
36 | * // Set the 1st week to 2 January 2005 with default options:
|
37 | * const result = setWeek(new Date(2005, 0, 2), 1)
|
38 | * //=> Sun Dec 26 2004 00:00:00
|
39 | *
|
40 | * @example
|
41 | * // Set the 1st week to 2 January 2005,
|
42 | * // if Monday is the first day of the week,
|
43 | * // and the first week of the year always contains 4 January:
|
44 | * const result = setWeek(new Date(2005, 0, 2), 1, {
|
45 | * weekStartsOn: 1,
|
46 | * firstWeekContainsDate: 4
|
47 | * })
|
48 | * //=> Sun Jan 4 2004 00:00:00
|
49 | */
|
50 | export declare function setWeek<DateType extends Date>(
|
51 | date: DateType | number | string,
|
52 | week: number,
|
53 | options?: SetWeekOptions,
|
54 | ): DateType;
|