isEqual.mjs 940 B

123456789101112131415161718192021222324252627282930313233
  1. import { toDate } from "./toDate.mjs";
  2. /**
  3. * @name isEqual
  4. * @category Common Helpers
  5. * @summary Are the given dates equal?
  6. *
  7. * @description
  8. * Are the given dates equal?
  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 dateLeft - The first date to compare
  13. * @param dateRight - The second date to compare
  14. *
  15. * @returns The dates are equal
  16. *
  17. * @example
  18. * // Are 2 July 2014 06:30:45.000 and 2 July 2014 06:30:45.500 equal?
  19. * const result = isEqual(
  20. * new Date(2014, 6, 2, 6, 30, 45, 0),
  21. * new Date(2014, 6, 2, 6, 30, 45, 500)
  22. * )
  23. * //=> false
  24. */
  25. export function isEqual(leftDate, rightDate) {
  26. const _dateLeft = toDate(leftDate);
  27. const _dateRight = toDate(rightDate);
  28. return +_dateLeft === +_dateRight;
  29. }
  30. // Fallback for modularized imports:
  31. export default isEqual;