isAfter.mjs 964 B

123456789101112131415161718192021222324252627282930
  1. import { toDate } from "./toDate.mjs";
  2. /**
  3. * @name isAfter
  4. * @category Common Helpers
  5. * @summary Is the first date after the second one?
  6. *
  7. * @description
  8. * Is the first date after the second one?
  9. *
  10. * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
  11. *
  12. * @param date - The date that should be after the other one to return true
  13. * @param dateToCompare - The date to compare with
  14. *
  15. * @returns The first date is after the second date
  16. *
  17. * @example
  18. * // Is 10 July 1989 after 11 February 1987?
  19. * const result = isAfter(new Date(1989, 6, 10), new Date(1987, 1, 11))
  20. * //=> true
  21. */
  22. export function isAfter(date, dateToCompare) {
  23. const _date = toDate(date);
  24. const _dateToCompare = toDate(dateToCompare);
  25. return _date.getTime() > _dateToCompare.getTime();
  26. }
  27. // Fallback for modularized imports:
  28. export default isAfter;