isBefore.js 951 B

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. exports.isBefore = isBefore;
  3. var _index = require("./toDate.js");
  4. /**
  5. * @name isBefore
  6. * @category Common Helpers
  7. * @summary Is the first date before the second one?
  8. *
  9. * @description
  10. * Is the first date before the second one?
  11. *
  12. * @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).
  13. *
  14. * @param date - The date that should be before the other one to return true
  15. * @param dateToCompare - The date to compare with
  16. *
  17. * @returns The first date is before the second date
  18. *
  19. * @example
  20. * // Is 10 July 1989 before 11 February 1987?
  21. * const result = isBefore(new Date(1989, 6, 10), new Date(1987, 1, 11))
  22. * //=> false
  23. */
  24. function isBefore(date, dateToCompare) {
  25. const _date = (0, _index.toDate)(date);
  26. const _dateToCompare = (0, _index.toDate)(dateToCompare);
  27. return +_date < +_dateToCompare;
  28. }