endOfYesterday.cjs 1.1 KB

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