index.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = eachWeekendOfYear;
  6. var _index = _interopRequireDefault(require("../eachWeekendOfInterval/index.js"));
  7. var _index2 = _interopRequireDefault(require("../startOfYear/index.js"));
  8. var _index3 = _interopRequireDefault(require("../endOfYear/index.js"));
  9. var _index4 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. /**
  12. * @name eachWeekendOfYear
  13. * @category Year Helpers
  14. * @summary List all the Saturdays and Sundays in the year.
  15. *
  16. * @description
  17. * Get all the Saturdays and Sundays in the year.
  18. *
  19. * @param {Date|Number} date - the given year
  20. * @returns {Date[]} an array containing all the Saturdays and Sundays
  21. * @throws {TypeError} 1 argument required
  22. * @throws {RangeError} The passed date is invalid
  23. *
  24. * @example
  25. * // Lists all Saturdays and Sundays in the year
  26. * var result = eachWeekendOfYear(new Date(2020, 1, 1))
  27. * //=> [
  28. * // Sat Jan 03 2020 00:00:00,
  29. * // Sun Jan 04 2020 00:00:00,
  30. * // ...
  31. * // Sun Dec 27 2020 00:00:00
  32. * // ]
  33. * ]
  34. */
  35. function eachWeekendOfYear(dirtyDate) {
  36. (0, _index4.default)(1, arguments);
  37. var startDate = (0, _index2.default)(dirtyDate);
  38. if (isNaN(startDate)) throw new RangeError('The passed date is invalid');
  39. var endDate = (0, _index3.default)(dirtyDate);
  40. return (0, _index.default)({
  41. start: startDate,
  42. end: endDate
  43. });
  44. }
  45. module.exports = exports.default;