startOfYesterday.mjs 672 B

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