Source: isYesterday/index.js

  1. import isSameDay from '../isSameDay/index'
  2. import subDays from '../subDays/index'
  3. import requiredArgs from '../_lib/requiredArgs/index'
  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. * ### v2.0.0 breaking changes:
  17. *
  18. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  19. *
  20. * @param {Date|Number} date - the date to check
  21. * @returns {Boolean} the date is yesterday
  22. * @throws {TypeError} 1 argument required
  23. *
  24. * @example
  25. * // If today is 6 October 2014, is 5 October 14:00:00 yesterday?
  26. * var result = isYesterday(new Date(2014, 9, 5, 14, 0))
  27. * //=> true
  28. */
  29. export default function isYesterday(dirtyDate) {
  30. requiredArgs(1, arguments)
  31. return isSameDay(dirtyDate, subDays(Date.now(), 1))
  32. }