isYesterday.js 909 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { constructFrom } from "./constructFrom.js";
  2. import { constructNow } from "./constructNow.js";
  3. import { isSameDay } from "./isSameDay.js";
  4. import { subDays } from "./subDays.js";
  5. /**
  6. * The {@link isYesterday} function options.
  7. */
  8. /**
  9. * @name isYesterday
  10. * @category Day Helpers
  11. * @summary Is the given date yesterday?
  12. * @pure false
  13. *
  14. * @description
  15. * Is the given date yesterday?
  16. *
  17. * @param date - The date to check
  18. * @param options - An object with options
  19. *
  20. * @returns The date is yesterday
  21. *
  22. * @example
  23. * // If today is 6 October 2014, is 5 October 14:00:00 yesterday?
  24. * const result = isYesterday(new Date(2014, 9, 5, 14, 0))
  25. * //=> true
  26. */
  27. export function isYesterday(date, options) {
  28. return isSameDay(
  29. constructFrom(options?.in || date, date),
  30. subDays(constructNow(options?.in || date), 1),
  31. );
  32. }
  33. // Fallback for modularized imports:
  34. export default isYesterday;