endOfDay.mjs 857 B

123456789101112131415161718192021222324252627282930
  1. import { toDate } from "./toDate.mjs";
  2. /**
  3. * @name endOfDay
  4. * @category Day Helpers
  5. * @summary Return the end of a day for the given date.
  6. *
  7. * @description
  8. * Return the end of a day for the given date.
  9. * The result will be in the local timezone.
  10. *
  11. * @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).
  12. *
  13. * @param date - The original date
  14. *
  15. * @returns The end of a day
  16. *
  17. * @example
  18. * // The end of a day for 2 September 2014 11:55:00:
  19. * const result = endOfDay(new Date(2014, 8, 2, 11, 55, 0))
  20. * //=> Tue Sep 02 2014 23:59:59.999
  21. */
  22. export function endOfDay(date) {
  23. const _date = toDate(date);
  24. _date.setHours(23, 59, 59, 999);
  25. return _date;
  26. }
  27. // Fallback for modularized imports:
  28. export default endOfDay;