endOfMinute.mjs 888 B

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