isYesterday.mjs 874 B

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