UNPKG

1.21 kBTypeScriptView Raw
1import type { LocalizedOptions, WeekOptions } from "./types.js";
2/**
3 * The {@link getWeeksInMonth} function options.
4 */
5export interface GetWeeksInMonthOptions
6 extends LocalizedOptions<"options">,
7 WeekOptions {}
8/**
9 * @name getWeeksInMonth
10 * @category Week Helpers
11 * @summary Get the number of calendar weeks a month spans.
12 *
13 * @description
14 * Get the number of calendar weeks the month in the given date spans.
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 given date
19 * @param options - An object with options.
20 *
21 * @returns The number of calendar weeks
22 *
23 * @example
24 * // How many calendar weeks does February 2015 span?
25 * const result = getWeeksInMonth(new Date(2015, 1, 8))
26 * //=> 4
27 *
28 * @example
29 * // If the week starts on Monday,
30 * // how many calendar weeks does July 2017 span?
31 * const result = getWeeksInMonth(new Date(2017, 6, 5), { weekStartsOn: 1 })
32 * //=> 6
33 */
34export declare function getWeeksInMonth<DateType extends Date>(
35 date: DateType | number | string,
36 options?: GetWeeksInMonthOptions,
37): number;