eachWeekendOfYear.mjs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { eachWeekendOfInterval } from "./eachWeekendOfInterval.mjs";
  2. import { endOfYear } from "./endOfYear.mjs";
  3. import { startOfYear } from "./startOfYear.mjs";
  4. /**
  5. * @name eachWeekendOfYear
  6. * @category Year Helpers
  7. * @summary List all the Saturdays and Sundays in the year.
  8. *
  9. * @description
  10. * Get all the Saturdays and Sundays in the year.
  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 year
  15. *
  16. * @returns An array containing all the Saturdays and Sundays
  17. *
  18. * @example
  19. * // Lists all Saturdays and Sundays in the year
  20. * const result = eachWeekendOfYear(new Date(2020, 1, 1))
  21. * //=> [
  22. * // Sat Jan 03 2020 00:00:00,
  23. * // Sun Jan 04 2020 00:00:00,
  24. * // ...
  25. * // Sun Dec 27 2020 00:00:00
  26. * // ]
  27. * ]
  28. */
  29. export function eachWeekendOfYear(date) {
  30. const start = startOfYear(date);
  31. const end = endOfYear(date);
  32. return eachWeekendOfInterval({ start, end });
  33. }
  34. // Fallback for modularized imports:
  35. export default eachWeekendOfYear;