endOfMinute.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { toDate } from "./toDate.js";
  2. /**
  3. * The {@link endOfMinute} function options.
  4. */
  5. /**
  6. * @name endOfMinute
  7. * @category Minute Helpers
  8. * @summary Return the end of a minute for the given date.
  9. *
  10. * @description
  11. * Return the end of a minute for the given date.
  12. * The result will be in the local timezone or the provided context.
  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 date - The original date
  18. * @param options - An object with options
  19. *
  20. * @returns The end of a minute
  21. *
  22. * @example
  23. * // The end of a minute for 1 December 2014 22:15:45.400:
  24. * const result = endOfMinute(new Date(2014, 11, 1, 22, 15, 45, 400))
  25. * //=> Mon Dec 01 2014 22:15:59.999
  26. */
  27. export function endOfMinute(date, options) {
  28. const _date = toDate(date, options?.in);
  29. _date.setSeconds(59, 999);
  30. return _date;
  31. }
  32. // Fallback for modularized imports:
  33. export default endOfMinute;