index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = setISODay;
  6. var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
  7. var _index2 = _interopRequireDefault(require("../toDate/index.js"));
  8. var _index3 = _interopRequireDefault(require("../addDays/index.js"));
  9. var _index4 = _interopRequireDefault(require("../getISODay/index.js"));
  10. var _index5 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12. /**
  13. * @name setISODay
  14. * @category Weekday Helpers
  15. * @summary Set the day of the ISO week to the given date.
  16. *
  17. * @description
  18. * Set the day of the ISO week to the given date.
  19. * ISO week starts with Monday.
  20. * 7 is the index of Sunday, 1 is the index of Monday etc.
  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 date to be changed
  27. * @param {Number} day - the day of the ISO week of the new date
  28. * @returns {Date} the new date with the day of the ISO week set
  29. * @throws {TypeError} 2 arguments required
  30. *
  31. * @example
  32. * // Set Sunday to 1 September 2014:
  33. * const result = setISODay(new Date(2014, 8, 1), 7)
  34. * //=> Sun Sep 07 2014 00:00:00
  35. */
  36. function setISODay(dirtyDate, dirtyDay) {
  37. (0, _index5.default)(2, arguments);
  38. var date = (0, _index2.default)(dirtyDate);
  39. var day = (0, _index.default)(dirtyDay);
  40. var currentDay = (0, _index4.default)(date);
  41. var diff = day - currentDay;
  42. return (0, _index3.default)(date, diff);
  43. }
  44. module.exports = exports.default;