index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import getISOWeekYear from "../getISOWeekYear/index.js";
  2. import startOfISOWeek from "../startOfISOWeek/index.js";
  3. import requiredArgs from "../_lib/requiredArgs/index.js";
  4. /**
  5. * @name startOfISOWeekYear
  6. * @category ISO Week-Numbering Year Helpers
  7. * @summary Return the start of an ISO week-numbering year for the given date.
  8. *
  9. * @description
  10. * Return the start of an ISO week-numbering year,
  11. * which always starts 3 days before the year's first Thursday.
  12. * The result will be in the local timezone.
  13. *
  14. * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
  15. *
  16. * @param {Date|Number} date - the original date
  17. * @returns {Date} the start of an ISO week-numbering year
  18. * @throws {TypeError} 1 argument required
  19. *
  20. * @example
  21. * // The start of an ISO week-numbering year for 2 July 2005:
  22. * const result = startOfISOWeekYear(new Date(2005, 6, 2))
  23. * //=> Mon Jan 03 2005 00:00:00
  24. */
  25. export default function startOfISOWeekYear(dirtyDate) {
  26. requiredArgs(1, arguments);
  27. var year = getISOWeekYear(dirtyDate);
  28. var fourthOfJanuary = new Date(0);
  29. fourthOfJanuary.setFullYear(year, 0, 4);
  30. fourthOfJanuary.setHours(0, 0, 0, 0);
  31. var date = startOfISOWeek(fourthOfJanuary);
  32. return date;
  33. }