index.js 914 B

1234567891011121314151617181920212223242526
  1. import toDate from "../toDate/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name isBefore
  5. * @category Common Helpers
  6. * @summary Is the first date before the second one?
  7. *
  8. * @description
  9. * Is the first date before the second one?
  10. *
  11. * @param {Date|Number} date - the date that should be before the other one to return true
  12. * @param {Date|Number} dateToCompare - the date to compare with
  13. * @returns {Boolean} the first date is before the second date
  14. * @throws {TypeError} 2 arguments required
  15. *
  16. * @example
  17. * // Is 10 July 1989 before 11 February 1987?
  18. * const result = isBefore(new Date(1989, 6, 10), new Date(1987, 1, 11))
  19. * //=> false
  20. */
  21. export default function isBefore(dirtyDate, dirtyDateToCompare) {
  22. requiredArgs(2, arguments);
  23. var date = toDate(dirtyDate);
  24. var dateToCompare = toDate(dirtyDateToCompare);
  25. return date.getTime() < dateToCompare.getTime();
  26. }