index.js 1.7 KB

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