compareTo method

  1. @override
int compareTo(
  1. LocalDateTime? other
)
override

Indicates whether this date/time is earlier, later or the same as another one.

Only date/time values within the same calendar systems can be compared with this method. Attempting to compare values within different calendars will fail with an ArgumentError. Ideally, comparisons is almost always preferable to continuing.

  • other: The other local date/time to compare with this value.

Returns: A value less than zero if this date/time is earlier than other; zero if this date/time is the same as other; a value greater than zero if this date/time is later than other.

  • ArgumentError: The calendar system of other is not the same as the calendar system of this value.

Implementation

@override
int compareTo(LocalDateTime? other) {
  // This will check calendars...
  if (other == null) return 1;
  int dateComparison = calendarDate.compareTo(other.calendarDate);
  if (dateComparison != 0) {
    return dateComparison;
  }
  return clockTime.compareTo(other.clockTime);
}