isBefore.mjs 956 B

123456789101112131415161718192021222324252627282930
  1. import { toDate } from "./toDate.mjs";
  2. /**
  3. * @name isBefore
  4. * @category Common Helpers
  5. * @summary Is the first date before the second one?
  6. *
  7. * @description
  8. * Is the first date before 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 before the other one to return true
  13. * @param dateToCompare - The date to compare with
  14. *
  15. * @returns The first date is before the second date
  16. *
  17. * @example
  18. * // Is 10 July 1989 before 11 February 1987?
  19. * const result = isBefore(new Date(1989, 6, 10), new Date(1987, 1, 11))
  20. * //=> false
  21. */
  22. export function isBefore(date, dateToCompare) {
  23. const _date = toDate(date);
  24. const _dateToCompare = toDate(dateToCompare);
  25. return +_date < +_dateToCompare;
  26. }
  27. // Fallback for modularized imports:
  28. export default isBefore;