endOfYesterday.js 1.1 KB

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