index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = startOfISOWeekYear;
  6. var _index = _interopRequireDefault(require("../getISOWeekYear/index.js"));
  7. var _index2 = _interopRequireDefault(require("../startOfISOWeek/index.js"));
  8. var _index3 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. /**
  11. * @name startOfISOWeekYear
  12. * @category ISO Week-Numbering Year Helpers
  13. * @summary Return the start of an ISO week-numbering year for the given date.
  14. *
  15. * @description
  16. * Return the start of an ISO week-numbering year,
  17. * which always starts 3 days before the year's first Thursday.
  18. * The result will be in the local timezone.
  19. *
  20. * ISO week-numbering year: http://en.wikipedia.org/wiki/ISO_week_date
  21. *
  22. * ### v2.0.0 breaking changes:
  23. *
  24. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  25. *
  26. * @param {Date|Number} date - the original date
  27. * @returns {Date} the start of an ISO week-numbering year
  28. * @throws {TypeError} 1 argument required
  29. *
  30. * @example
  31. * // The start of an ISO week-numbering year for 2 July 2005:
  32. * const result = startOfISOWeekYear(new Date(2005, 6, 2))
  33. * //=> Mon Jan 03 2005 00:00:00
  34. */
  35. function startOfISOWeekYear(dirtyDate) {
  36. (0, _index3.default)(1, arguments);
  37. var year = (0, _index.default)(dirtyDate);
  38. var fourthOfJanuary = new Date(0);
  39. fourthOfJanuary.setFullYear(year, 0, 4);
  40. fourthOfJanuary.setHours(0, 0, 0, 0);
  41. var date = (0, _index2.default)(fourthOfJanuary);
  42. return date;
  43. }
  44. module.exports = exports.default;