eachWeekendOfMonth.js 1.3 KB

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