startOfYesterday.cjs 935 B

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