compareAsc.d.mts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * @name compareAsc
  3. * @category Common Helpers
  4. * @summary Compare the two dates and return -1, 0 or 1.
  5. *
  6. * @description
  7. * Compare the two dates and return 1 if the first date is after the second,
  8. * -1 if the first date is before the second or 0 if dates are 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 result of the comparison
  16. *
  17. * @example
  18. * // Compare 11 February 1987 and 10 July 1989:
  19. * const result = compareAsc(new Date(1987, 1, 11), new Date(1989, 6, 10))
  20. * //=> -1
  21. *
  22. * @example
  23. * // Sort the array of dates:
  24. * const result = [
  25. * new Date(1995, 6, 2),
  26. * new Date(1987, 1, 11),
  27. * new Date(1989, 6, 10)
  28. * ].sort(compareAsc)
  29. * //=> [
  30. * // Wed Feb 11 1987 00:00:00,
  31. * // Mon Jul 10 1989 00:00:00,
  32. * // Sun Jul 02 1995 00:00:00
  33. * // ]
  34. */
  35. export declare function compareAsc<DateType extends Date>(
  36. dateLeft: DateType | number | string,
  37. dateRight: DateType | number | string,
  38. ): number;