eachWeekendOfMonth.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { eachWeekendOfInterval } from "./eachWeekendOfInterval.js";
  2. import { endOfMonth } from "./endOfMonth.js";
  3. import { startOfMonth } from "./startOfMonth.js";
  4. /**
  5. * The {@link eachWeekendOfMonth} function options.
  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. * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
  17. *
  18. * @param date - The given month
  19. * @param options - An object with options
  20. *
  21. * @returns An array containing all the Saturdays and Sundays
  22. *
  23. * @example
  24. * // Lists all Saturdays and Sundays in the given month
  25. * const result = eachWeekendOfMonth(new Date(2022, 1, 1))
  26. * //=> [
  27. * // Sat Feb 05 2022 00:00:00,
  28. * // Sun Feb 06 2022 00:00:00,
  29. * // Sat Feb 12 2022 00:00:00,
  30. * // Sun Feb 13 2022 00:00:00,
  31. * // Sat Feb 19 2022 00:00:00,
  32. * // Sun Feb 20 2022 00:00:00,
  33. * // Sat Feb 26 2022 00:00:00,
  34. * // Sun Feb 27 2022 00:00:00
  35. * // ]
  36. */
  37. export function eachWeekendOfMonth(date, options) {
  38. const start = startOfMonth(date, options);
  39. const end = endOfMonth(date, options);
  40. return eachWeekendOfInterval({ start, end }, options);
  41. }
  42. // Fallback for modularized imports:
  43. export default eachWeekendOfMonth;