eachWeekendOfMonth.mjs 1.3 KB

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