endOfSecond.mjs 889 B

123456789101112131415161718192021222324252627282930
  1. import { toDate } from "./toDate.mjs";
  2. /**
  3. * @name endOfSecond
  4. * @category Second Helpers
  5. * @summary Return the end of a second for the given date.
  6. *
  7. * @description
  8. * Return the end of a second 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 second
  16. *
  17. * @example
  18. * // The end of a second for 1 December 2014 22:15:45.400:
  19. * const result = endOfSecond(new Date(2014, 11, 1, 22, 15, 45, 400))
  20. * //=> Mon Dec 01 2014 22:15:45.999
  21. */
  22. export function endOfSecond(date) {
  23. const _date = toDate(date);
  24. _date.setMilliseconds(999);
  25. return _date;
  26. }
  27. // Fallback for modularized imports:
  28. export default endOfSecond;