compareTo method
Compares two LocalDateTime instances chronologically.
Returns a negative number if this is earlier, 0 if equal, positive if later.
Example:
final dt1 = LocalDateTime.of(2024, 6, 27, 14, 30);
final dt2 = LocalDateTime.of(2024, 6, 27, 15, 30);
print(dt1.compareTo(dt2)); // -1
print(dt2.compareTo(dt1)); // 1
Implementation
@override
int compareTo(LocalDateTime other) {
int result = date.compareTo(other.date);
if (result.isNotEqualTo(0)) return result;
return time.compareTo(other.time);
}