endOfYesterday.mjs 851 B

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