nextDay.cjs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. exports.nextDay = nextDay;
  3. var _index = require("./addDays.cjs");
  4. var _index2 = require("./getDay.cjs");
  5. /**
  6. * The {@link nextDay} function options.
  7. */
  8. /**
  9. * @name nextDay
  10. * @category Weekday Helpers
  11. * @summary When is the next day of the week? 0-6 the day of the week, 0 represents Sunday.
  12. *
  13. * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
  14. * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
  15. *
  16. * @param date - The date to check
  17. * @param day - Day of the week
  18. * @param options - An object with options
  19. *
  20. * @returns The date is the next day of the week
  21. *
  22. * @example
  23. * // When is the next Monday after Mar, 20, 2020?
  24. * const result = nextDay(new Date(2020, 2, 20), 1)
  25. * //=> Mon Mar 23 2020 00:00:00
  26. *
  27. * @example
  28. * // When is the next Tuesday after Mar, 21, 2020?
  29. * const result = nextDay(new Date(2020, 2, 21), 2)
  30. * //=> Tue Mar 24 2020 00:00:00
  31. */
  32. function nextDay(date, day, options) {
  33. let delta = day - (0, _index2.getDay)(date, options);
  34. if (delta <= 0) delta += 7;
  35. return (0, _index.addDays)(date, delta, options);
  36. }