UNPKG

1.83 kBTypeScriptView Raw
1import type {
2 FirstWeekContainsDateOptions,
3 LocalizedOptions,
4 WeekOptions,
5} from "./types.js";
6/**
7 * The {@link getWeekYear} function options.
8 */
9export interface GetWeekYearOptions
10 extends LocalizedOptions<"options">,
11 WeekOptions,
12 FirstWeekContainsDateOptions {}
13/**
14 * @name getWeekYear
15 * @category Week-Numbering Year Helpers
16 * @summary Get the local week-numbering year of the given date.
17 *
18 * @description
19 * Get the local week-numbering year of the given date.
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 given date
30 * @param options - An object with options.
31 *
32 * @returns The local week-numbering year
33 *
34 * @example
35 * // Which week numbering year is 26 December 2004 with the default settings?
36 * const result = getWeekYear(new Date(2004, 11, 26))
37 * //=> 2005
38 *
39 * @example
40 * // Which week numbering year is 26 December 2004 if week starts on Saturday?
41 * const result = getWeekYear(new Date(2004, 11, 26), { weekStartsOn: 6 })
42 * //=> 2004
43 *
44 * @example
45 * // Which week numbering year is 26 December 2004 if the first week contains 4 January?
46 * const result = getWeekYear(new Date(2004, 11, 26), { firstWeekContainsDate: 4 })
47 * //=> 2004
48 */
49export declare function getWeekYear<DateType extends Date>(
50 date: DateType | number | string,
51 options?: GetWeekYearOptions,
52): number;