index.js 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. import toDate from "../toDate/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name isAfter
  5. * @category Common Helpers
  6. * @summary Is the first date after the second one?
  7. *
  8. * @description
  9. * Is the first date after the second one?
  10. *
  11. * ### v2.0.0 breaking changes:
  12. *
  13. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  14. *
  15. * @param {Date|Number} date - the date that should be after the other one to return true
  16. * @param {Date|Number} dateToCompare - the date to compare with
  17. * @returns {Boolean} the first date is after the second date
  18. * @throws {TypeError} 2 arguments required
  19. *
  20. * @example
  21. * // Is 10 July 1989 after 11 February 1987?
  22. * var result = isAfter(new Date(1989, 6, 10), new Date(1987, 1, 11))
  23. * //=> true
  24. */
  25. export default function isAfter(dirtyDate, dirtyDateToCompare) {
  26. requiredArgs(2, arguments);
  27. var date = toDate(dirtyDate);
  28. var dateToCompare = toDate(dirtyDateToCompare);
  29. return date.getTime() > dateToCompare.getTime();
  30. }