index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import eachWeekendOfInterval from "../eachWeekendOfInterval/index.js";
  2. import endOfYear from "../endOfYear/index.js";
  3. import startOfYear from "../startOfYear/index.js";
  4. import requiredArgs from "../_lib/requiredArgs/index.js";
  5. /**
  6. * @name eachWeekendOfYear
  7. * @category Year Helpers
  8. * @summary List all the Saturdays and Sundays in the year.
  9. *
  10. * @description
  11. * Get all the Saturdays and Sundays in the year.
  12. *
  13. * @param {Date|Number} date - the given year
  14. * @returns {Date[]} an array containing all the Saturdays and Sundays
  15. * @throws {TypeError} 1 argument required
  16. * @throws {RangeError} The passed date is invalid
  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 default function eachWeekendOfYear(dirtyDate) {
  30. requiredArgs(1, arguments);
  31. var startDate = startOfYear(dirtyDate);
  32. var endDate = endOfYear(dirtyDate);
  33. return eachWeekendOfInterval({
  34. start: startDate,
  35. end: endDate
  36. });
  37. }