Skip to content

@jsvision/ui / compare

Function: compare()

compare(a, b): -1 | 0 | 1

Defined in: ui/src/date/calendar-date.ts:153

Order two dates: -1 if a<b, 0 if equal, +1 if a>b (compared by year, then month, then day).

Parameters

a

CalendarDate

The left date.

b

CalendarDate

The right date.

Returns

-1 | 0 | 1

-1 | 0 | 1.

Example

ts
compare({ year: 2026, month: 7, day: 8 }, { year: 2026, month: 7, day: 9 }); // -1
// Sort an array of dates ascending:
dates.sort(compare);