startOfYesterday.js 936 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { constructNow } from "./constructNow.js";
  2. /**
  3. * The {@link startOfYesterday} function options.
  4. */
  5. /**
  6. * @name startOfYesterday
  7. * @category Day Helpers
  8. * @summary Return the start of yesterday.
  9. * @pure false
  10. *
  11. * @typeParam ContextDate - The `Date` type of the context function.
  12. *
  13. * @param options - An object with options
  14. *
  15. * @description
  16. * Return the start of yesterday.
  17. *
  18. * @returns The start of yesterday
  19. *
  20. * @example
  21. * // If today is 6 October 2014:
  22. * const result = startOfYesterday()
  23. * //=> Sun Oct 5 2014 00:00:00
  24. */
  25. export function startOfYesterday(options) {
  26. const now = constructNow(options?.in);
  27. const year = now.getFullYear();
  28. const month = now.getMonth();
  29. const day = now.getDate();
  30. const date = constructNow(options?.in);
  31. date.setFullYear(year, month, day - 1);
  32. date.setHours(0, 0, 0, 0);
  33. return date;
  34. }
  35. // Fallback for modularized imports:
  36. export default startOfYesterday;