index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. * ### v2.0.0 breaking changes:
  17. *
  18. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  19. *
  20. * @param {Date|Number} date - the original date
  21. * @returns {Date} the start of an ISO week-numbering year
  22. * @throws {TypeError} 1 argument required
  23. *
  24. * @example
  25. * // The start of an ISO week-numbering year for 2 July 2005:
  26. * const result = startOfISOWeekYear(new Date(2005, 6, 2))
  27. * //=> Mon Jan 03 2005 00:00:00
  28. */
  29. export default function startOfISOWeekYear(dirtyDate) {
  30. requiredArgs(1, arguments);
  31. var year = getISOWeekYear(dirtyDate);
  32. var fourthOfJanuary = new Date(0);
  33. fourthOfJanuary.setFullYear(year, 0, 4);
  34. fourthOfJanuary.setHours(0, 0, 0, 0);
  35. var date = startOfISOWeek(fourthOfJanuary);
  36. return date;
  37. }