compareTo method

  1. @override
int compareTo(
  1. TimeOfDay other
)
override

Compares this TimeOfDay object to other independent of date.

Does not account for day or sub-minute differences. This means that "00:00" of the next day is still before "23:00" of this day.

A compareTo function returns:

  • a negative value if this TimeOfDay isBefore other.
  • 0 if this DateTime isAtSameTimeAs other, and
  • a positive value otherwise (when this TimeOfDay isAfter other).

Implementation

@override
int compareTo(TimeOfDay other) {
  final int hourComparison = hour.compareTo(other.hour);
  return hourComparison == 0 ? minute.compareTo(other.minute) : hourComparison;
}