index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = nextDay;
  7. var _index = _interopRequireDefault(require("../addDays/index.js"));
  8. var _index2 = _interopRequireDefault(require("../getDay/index.js"));
  9. var _index3 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  10. /**
  11. * @name nextDay
  12. * @category Weekday Helpers
  13. * @summary When is the next day of the week?
  14. *
  15. * @description
  16. * When is the next day of the week? 0-6 the day of the week, 0 represents Sunday.
  17. *
  18. * @param {Date | number} date - the date to check
  19. * @param {Day} day - day of the week
  20. * @returns {Date} - the date is the next day of week
  21. * @throws {TypeError} - 2 arguments required
  22. *
  23. * @example
  24. * // When is the next Monday after Mar, 20, 2020?
  25. * const result = nextDay(new Date(2020, 2, 20), 1)
  26. * //=> Mon Mar 23 2020 00:00:00
  27. *
  28. * @example
  29. * // When is the next Tuesday after Mar, 21, 2020?
  30. * const result = nextDay(new Date(2020, 2, 21), 2)
  31. * //=> Tue Mar 24 2020 00:00:00
  32. */
  33. function nextDay(date, day) {
  34. (0, _index3.default)(2, arguments);
  35. var delta = day - (0, _index2.default)(date);
  36. if (delta <= 0) delta += 7;
  37. return (0, _index.default)(date, delta);
  38. }
  39. module.exports = exports.default;