isYesterday.js 887 B

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. exports.isYesterday = isYesterday;
  3. var _index = require("./constructNow.js");
  4. var _index2 = require("./isSameDay.js");
  5. var _index3 = require("./subDays.js");
  6. /**
  7. * @name isYesterday
  8. * @category Day Helpers
  9. * @summary Is the given date yesterday?
  10. * @pure false
  11. *
  12. * @description
  13. * Is the given date yesterday?
  14. *
  15. * @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).
  16. *
  17. * @param date - The date to check
  18. *
  19. * @returns The date is yesterday
  20. *
  21. * @example
  22. * // If today is 6 October 2014, is 5 October 14:00:00 yesterday?
  23. * const result = isYesterday(new Date(2014, 9, 5, 14, 0))
  24. * //=> true
  25. */
  26. function isYesterday(date) {
  27. return (0, _index2.isSameDay)(
  28. date,
  29. (0, _index3.subDays)((0, _index.constructNow)(date), 1),
  30. );
  31. }