index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = getUTCISOWeekYear;
  6. var _index = _interopRequireDefault(require("../../toDate/index.js"));
  7. var _index2 = _interopRequireDefault(require("../startOfUTCISOWeek/index.js"));
  8. var _index3 = _interopRequireDefault(require("../requiredArgs/index.js"));
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. // This function will be a part of public API when UTC function will be implemented.
  11. // See issue: https://github.com/date-fns/date-fns/issues/376
  12. function getUTCISOWeekYear(dirtyDate) {
  13. (0, _index3.default)(1, arguments);
  14. var date = (0, _index.default)(dirtyDate);
  15. var year = date.getUTCFullYear();
  16. var fourthOfJanuaryOfNextYear = new Date(0);
  17. fourthOfJanuaryOfNextYear.setUTCFullYear(year + 1, 0, 4);
  18. fourthOfJanuaryOfNextYear.setUTCHours(0, 0, 0, 0);
  19. var startOfNextYear = (0, _index2.default)(fourthOfJanuaryOfNextYear);
  20. var fourthOfJanuaryOfThisYear = new Date(0);
  21. fourthOfJanuaryOfThisYear.setUTCFullYear(year, 0, 4);
  22. fourthOfJanuaryOfThisYear.setUTCHours(0, 0, 0, 0);
  23. var startOfThisYear = (0, _index2.default)(fourthOfJanuaryOfThisYear);
  24. if (date.getTime() >= startOfNextYear.getTime()) {
  25. return year + 1;
  26. } else if (date.getTime() >= startOfThisYear.getTime()) {
  27. return year;
  28. } else {
  29. return year - 1;
  30. }
  31. }
  32. module.exports = exports.default;