compareDesc.d.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * @name compareDesc
  3. * @category Common Helpers
  4. * @summary Compare the two dates reverse chronologically 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 reverse chronologically:
  19. * const result = compareDesc(new Date(1987, 1, 11), new Date(1989, 6, 10))
  20. * //=> 1
  21. *
  22. * @example
  23. * // Sort the array of dates in reverse chronological order:
  24. * const result = [
  25. * new Date(1995, 6, 2),
  26. * new Date(1987, 1, 11),
  27. * new Date(1989, 6, 10)
  28. * ].sort(compareDesc)
  29. * //=> [
  30. * // Sun Jul 02 1995 00:00:00,
  31. * // Mon Jul 10 1989 00:00:00,
  32. * // Wed Feb 11 1987 00:00:00
  33. * // ]
  34. */
  35. export declare function compareDesc<DateType extends Date>(
  36. dateLeft: DateType | number | string,
  37. dateRight: DateType | number | string,
  38. ): number;