UNPKG

1.3 kBJavaScriptView Raw
1"use strict";
2exports.eachWeekendOfMonth = eachWeekendOfMonth;
3var _index = require("./eachWeekendOfInterval.js");
4var _index2 = require("./endOfMonth.js");
5var _index3 = require("./startOfMonth.js");
6
7/**
8 * @name eachWeekendOfMonth
9 * @category Month Helpers
10 * @summary List all the Saturdays and Sundays in the given month.
11 *
12 * @description
13 * Get all the Saturdays and Sundays in the given month.
14 *
15 * @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).
16 *
17 * @param date - The given month
18 *
19 * @returns An array containing all the Saturdays and Sundays
20 *
21 * @example
22 * // Lists all Saturdays and Sundays in the given month
23 * const result = eachWeekendOfMonth(new Date(2022, 1, 1))
24 * //=> [
25 * // Sat Feb 05 2022 00:00:00,
26 * // Sun Feb 06 2022 00:00:00,
27 * // Sat Feb 12 2022 00:00:00,
28 * // Sun Feb 13 2022 00:00:00,
29 * // Sat Feb 19 2022 00:00:00,
30 * // Sun Feb 20 2022 00:00:00,
31 * // Sat Feb 26 2022 00:00:00,
32 * // Sun Feb 27 2022 00:00:00
33 * // ]
34 */
35function eachWeekendOfMonth(date) {
36 const start = (0, _index3.startOfMonth)(date);
37 const end = (0, _index2.endOfMonth)(date);
38 return (0, _index.eachWeekendOfInterval)({ start, end });
39}