index.js 652 B

123456789101112131415161718192021222324
  1. var startOfDay = require('../start_of_day/index.js')
  2. /**
  3. * @category Day Helpers
  4. * @summary Is the given date yesterday?
  5. *
  6. * @description
  7. * Is the given date yesterday?
  8. *
  9. * @param {Date|String|Number} date - the date to check
  10. * @returns {Boolean} the date is yesterday
  11. *
  12. * @example
  13. * // If today is 6 October 2014, is 5 October 14:00:00 yesterday?
  14. * var result = isYesterday(new Date(2014, 9, 5, 14, 0))
  15. * //=> true
  16. */
  17. function isYesterday (dirtyDate) {
  18. var yesterday = new Date()
  19. yesterday.setDate(yesterday.getDate() - 1)
  20. return startOfDay(dirtyDate).getTime() === startOfDay(yesterday).getTime()
  21. }
  22. module.exports = isYesterday