endOfTomorrow.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { constructNow } from "./constructNow.js";
  2. /**
  3. * The {@link endOfTomorrow} function options.
  4. */
  5. /**
  6. * @name endOfTomorrow
  7. * @category Day Helpers
  8. * @summary Return the end of tomorrow.
  9. * @pure false
  10. *
  11. * @description
  12. * Return the end of tomorrow.
  13. *
  14. * @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).
  15. * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
  16. *
  17. * @param options - The options
  18. * @returns The end of tomorrow
  19. *
  20. * @example
  21. * // If today is 6 October 2014:
  22. * const result = endOfTomorrow()
  23. * //=> Tue Oct 7 2014 23:59:59.999
  24. */
  25. export function endOfTomorrow(options) {
  26. const now = constructNow(options?.in);
  27. const year = now.getFullYear();
  28. const month = now.getMonth();
  29. const day = now.getDate();
  30. const date = constructNow(options?.in);
  31. date.setFullYear(year, month, day + 1);
  32. date.setHours(23, 59, 59, 999);
  33. return options?.in ? options.in(date) : date;
  34. }
  35. // Fallback for modularized imports:
  36. export default endOfTomorrow;