UNPKG

1.74 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = eachWeekendOfMonth;
7
8var _index = _interopRequireDefault(require("../eachWeekendOfInterval/index.js"));
9
10var _index2 = _interopRequireDefault(require("../startOfMonth/index.js"));
11
12var _index3 = _interopRequireDefault(require("../endOfMonth/index.js"));
13
14var _index4 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
15
16function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
18/**
19 * @name eachWeekendOfMonth
20 * @category Month Helpers
21 * @summary List all the Saturdays and Sundays in the given month.
22 *
23 * @description
24 * Get all the Saturdays and Sundays in the given month.
25 *
26 * @param {Date|Number} date - the given month
27 * @returns {Date[]} an array containing all the Saturdays and Sundays
28 * @throws {TypeError} 1 argument required
29 * @throws {RangeError} The passed date is invalid
30 *
31 * @example
32 * // Lists all Saturdays and Sundays in the given month
33 * var result = eachWeekendOfMonth(new Date(2022, 1, 1))
34 * //=> [
35 * // Sat Feb 05 2022 00:00:00,
36 * // Sun Feb 06 2022 00:00:00,
37 * // Sat Feb 12 2022 00:00:00,
38 * // Sun Feb 13 2022 00:00:00,
39 * // Sat Feb 19 2022 00:00:00,
40 * // Sun Feb 20 2022 00:00:00,
41 * // Sat Feb 26 2022 00:00:00,
42 * // Sun Feb 27 2022 00:00:00
43 * // ]
44 */
45function eachWeekendOfMonth(dirtyDate) {
46 (0, _index4.default)(1, arguments);
47 var startDate = (0, _index2.default)(dirtyDate);
48 if (isNaN(startDate)) throw new RangeError('The passed date is invalid');
49 var endDate = (0, _index3.default)(dirtyDate);
50 return (0, _index.default)({
51 start: startDate,
52 end: endDate
53 });
54}
55
56module.exports = exports.default;
\No newline at end of file