eachWeekendOfYear.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { eachWeekendOfInterval } from "./eachWeekendOfInterval.js";
  2. import { endOfYear } from "./endOfYear.js";
  3. import { startOfYear } from "./startOfYear.js";
  4. /**
  5. * The {@link eachWeekendOfYear} function options.
  6. */
  7. /**
  8. * @name eachWeekendOfYear
  9. * @category Year Helpers
  10. * @summary List all the Saturdays and Sundays in the year.
  11. *
  12. * @description
  13. * Get all the Saturdays and Sundays in the year.
  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 year
  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 year
  25. * const result = eachWeekendOfYear(new Date(2020, 1, 1))
  26. * //=> [
  27. * // Sat Jan 03 2020 00:00:00,
  28. * // Sun Jan 04 2020 00:00:00,
  29. * // ...
  30. * // Sun Dec 27 2020 00:00:00
  31. * // ]
  32. * ]
  33. */
  34. export function eachWeekendOfYear(date, options) {
  35. const start = startOfYear(date, options);
  36. const end = endOfYear(date, options);
  37. return eachWeekendOfInterval({ start, end }, options);
  38. }
  39. // Fallback for modularized imports:
  40. export default eachWeekendOfYear;