UNPKG

1.6 kBJavaScriptView Raw
1import { eachWeekendOfInterval } from "./eachWeekendOfInterval.js";
2import { endOfMonth } from "./endOfMonth.js";
3import { startOfMonth } from "./startOfMonth.js";
4
5/**
6 * The {@link eachWeekendOfMonth} function options.
7 */
8
9/**
10 * @name eachWeekendOfMonth
11 * @category Month Helpers
12 * @summary List all the Saturdays and Sundays in the given month.
13 *
14 * @description
15 * Get all the Saturdays and Sundays in the given month.
16 *
17 * @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).
18 * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
19 *
20 * @param date - The given month
21 * @param options - An object with options
22 *
23 * @returns An array containing all the Saturdays and Sundays
24 *
25 * @example
26 * // Lists all Saturdays and Sundays in the given month
27 * const result = eachWeekendOfMonth(new Date(2022, 1, 1))
28 * //=> [
29 * // Sat Feb 05 2022 00:00:00,
30 * // Sun Feb 06 2022 00:00:00,
31 * // Sat Feb 12 2022 00:00:00,
32 * // Sun Feb 13 2022 00:00:00,
33 * // Sat Feb 19 2022 00:00:00,
34 * // Sun Feb 20 2022 00:00:00,
35 * // Sat Feb 26 2022 00:00:00,
36 * // Sun Feb 27 2022 00:00:00
37 * // ]
38 */
39export function eachWeekendOfMonth(date, options) {
40 const start = startOfMonth(date, options);
41 const end = endOfMonth(date, options);
42 return eachWeekendOfInterval({ start, end }, options);
43}
44
45// Fallback for modularized imports:
46export default eachWeekendOfMonth;