index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = setUTCISODay;
  6. var _index = _interopRequireDefault(require("../toInteger/index.js"));
  7. var _index2 = _interopRequireDefault(require("../../toDate/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 setUTCISODay(dirtyDate, dirtyDay) {
  13. (0, _index3.default)(2, arguments);
  14. var day = (0, _index.default)(dirtyDay);
  15. if (day % 7 === 0) {
  16. day = day - 7;
  17. }
  18. var weekStartsOn = 1;
  19. var date = (0, _index2.default)(dirtyDate);
  20. var currentDay = date.getUTCDay();
  21. var remainder = day % 7;
  22. var dayIndex = (remainder + 7) % 7;
  23. var diff = (dayIndex < weekStartsOn ? 7 : 0) + day - currentDay;
  24. date.setUTCDate(date.getUTCDate() + diff);
  25. return date;
  26. }
  27. module.exports = exports.default;