UNPKG

1.67 kBTypeScriptView Raw
1import type {
2 ContextOptions,
3 DateArg,
4 FirstWeekContainsDateOptions,
5 LocalizedOptions,
6 WeekOptions,
7} from "./types.js";
8/**
9 * The {@link getWeekYear} function options.
10 */
11export interface GetWeekYearOptions
12 extends LocalizedOptions<"options">,
13 WeekOptions,
14 FirstWeekContainsDateOptions,
15 ContextOptions<Date> {}
16/**
17 * @name getWeekYear
18 * @category Week-Numbering Year Helpers
19 * @summary Get the local week-numbering year of the given date.
20 *
21 * @description
22 * Get the local week-numbering year of the given date.
23 * The exact calculation depends on the values of
24 * `options.weekStartsOn` (which is the index of the first day of the week)
25 * and `options.firstWeekContainsDate` (which is the day of January, which is always in
26 * the first week of the week-numbering year)
27 *
28 * Week numbering: https://en.wikipedia.org/wiki/Week#The_ISO_week_date_system
29 *
30 * @param date - The given date
31 * @param options - An object with options.
32 *
33 * @returns The local week-numbering year
34 *
35 * @example
36 * // Which week numbering year is 26 December 2004 with the default settings?
37 * const result = getWeekYear(new Date(2004, 11, 26))
38 * //=> 2005
39 *
40 * @example
41 * // Which week numbering year is 26 December 2004 if week starts on Saturday?
42 * const result = getWeekYear(new Date(2004, 11, 26), { weekStartsOn: 6 })
43 * //=> 2004
44 *
45 * @example
46 * // Which week numbering year is 26 December 2004 if the first week contains 4 January?
47 * const result = getWeekYear(new Date(2004, 11, 26), { firstWeekContainsDate: 4 })
48 * //=> 2004
49 */
50export declare function getWeekYear(
51 date: DateArg<Date> & {},
52 options?: GetWeekYearOptions,
53): number;