startOfISOWeekYear.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. exports.startOfISOWeekYear = startOfISOWeekYear;
  3. var _index = require("./getISOWeekYear.js");
  4. var _index2 = require("./startOfISOWeek.js");
  5. var _index3 = require("./constructFrom.js");
  6. /**
  7. * @name startOfISOWeekYear
  8. * @category ISO Week-Numbering Year Helpers
  9. * @summary Return the start of an ISO week-numbering year for the given date.
  10. *
  11. * @description
  12. * Return the start of an ISO week-numbering year,
  13. * which always starts 3 days before the year's first Thursday.
  14. * The result will be in the local timezone.
  15. *
  16. * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
  17. *
  18. * @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).
  19. *
  20. * @param date - The original date
  21. *
  22. * @returns The start of an ISO week-numbering year
  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. function startOfISOWeekYear(date) {
  30. const year = (0, _index.getISOWeekYear)(date);
  31. const fourthOfJanuary = (0, _index3.constructFrom)(date, 0);
  32. fourthOfJanuary.setFullYear(year, 0, 4);
  33. fourthOfJanuary.setHours(0, 0, 0, 0);
  34. return (0, _index2.startOfISOWeek)(fourthOfJanuary);
  35. }