eachWeekendOfMonth.cjs 1.6 KB

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