compareTo method
Indicates whether this date is earlier, later or the same as another one.
Only dates within the same calendar systems can be compared with this method. Attempting to compare
dates within different calendars will fail with an ArgumentException
. Ideally, comparisons
between values in different calendars would be a compile-time failure, but failing at execution time
is almost always preferable to continuing.
other
: The other date to compare this one with
Returns: a value less than zero if this date is earlier than other
;
zero if this date is the same as other
; a value greater than zero if this date is
later than other
.
ArgumentException
: The calendar system ofother
is not the same as the calendar system of this value.
Implementation
@override
int compareTo(LocalDate? other)
{
// todo: is this the best way? Should I add a check like this everywhere?
if (other == null) return 1;
Preconditions.checkArgument(calendar == other.calendar, 'other', "Only values with the same calendar system can be compared");
return ICalendarSystem.compare(calendar, _yearMonthDay, other._yearMonthDay);
}