index.js 900 B

12345678910111213141516171819202122232425262728
  1. import isSameDay from "../isSameDay/index.js";
  2. import subDays from "../subDays/index.js";
  3. import requiredArgs from "../_lib/requiredArgs/index.js";
  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. * > ⚠️ Please note that this function is not present in the FP submodule as
  14. * > it uses `Date.now()` internally hence impure and can't be safely curried.
  15. *
  16. * @param {Date|Number} date - the date to check
  17. * @returns {Boolean} the date is yesterday
  18. * @throws {TypeError} 1 argument required
  19. *
  20. * @example
  21. * // If today is 6 October 2014, is 5 October 14:00:00 yesterday?
  22. * const result = isYesterday(new Date(2014, 9, 5, 14, 0))
  23. * //=> true
  24. */
  25. export default function isYesterday(dirtyDate) {
  26. requiredArgs(1, arguments);
  27. return isSameDay(dirtyDate, subDays(Date.now(), 1));
  28. }