endOfYesterday.js 830 B

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. exports.endOfYesterday = endOfYesterday; /**
  3. * @name endOfYesterday
  4. * @category Day Helpers
  5. * @summary Return the end of yesterday.
  6. * @pure false
  7. *
  8. * @description
  9. * Return the end of yesterday.
  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. * @returns The end of yesterday
  14. *
  15. * @example
  16. * // If today is 6 October 2014:
  17. * const result = endOfYesterday()
  18. * //=> Sun Oct 5 2014 23:59:59.999
  19. */
  20. function endOfYesterday() {
  21. const now = new Date();
  22. const year = now.getFullYear();
  23. const month = now.getMonth();
  24. const day = now.getDate();
  25. const date = new Date(0);
  26. date.setFullYear(year, month, day - 1);
  27. date.setHours(23, 59, 59, 999);
  28. return date;
  29. }