index.js 786 B

12345678910111213141516171819202122232425
  1. var parse = require('../parse/index.js')
  2. /**
  3. * @category Common Helpers
  4. * @summary Is the first date before the second one?
  5. *
  6. * @description
  7. * Is the first date before the second one?
  8. *
  9. * @param {Date|String|Number} date - the date that should be before the other one to return true
  10. * @param {Date|String|Number} dateToCompare - the date to compare with
  11. * @returns {Boolean} the first date is before the second date
  12. *
  13. * @example
  14. * // Is 10 July 1989 before 11 February 1987?
  15. * var result = isBefore(new Date(1989, 6, 10), new Date(1987, 1, 11))
  16. * //=> false
  17. */
  18. function isBefore (dirtyDate, dirtyDateToCompare) {
  19. var date = parse(dirtyDate)
  20. var dateToCompare = parse(dirtyDateToCompare)
  21. return date.getTime() < dateToCompare.getTime()
  22. }
  23. module.exports = isBefore