comparePointTimes function Null safety

TimeComparisonResult comparePointTimes(
  1. GpsPoint itemA,
  2. GpsPoint itemB
)

Compares the time values of itemA and itemB and returns the result.

Implemented to handle correct comparisons for types that have just one time field (GpsPoint, GpsMeasurement) and types that have a secondary time field as well (GpsStay).

Implementation

TimeComparisonResult comparePointTimes(GpsPoint itemA, GpsPoint itemB) {
  // Comparing GpsStay to non-stay items requires special care, because a stay
  // may overlap a GpsPoint, but the GpsPoint doesn't know about overlapping.
  if (itemA is GpsStay) {
    final startA = itemA.time.secondsSinceEpoch;
    final endA = itemA.endTime.secondsSinceEpoch;
    final startB = itemB.time.secondsSinceEpoch;
    final endB = itemB.endTime.secondsSinceEpoch;
    return compareTimeSpans(
        startA: startA, endA: endA, startB: startB, endB: endB);
  } else if (itemB is GpsStay) {
    // Put itemB in the lead of the comparison and simply invert the result.
    return opposite(comparePointTimes(itemB, itemA));
  }

  // Non-GpsStay items can be compared simply.
  return compareTime(itemA.time, itemB.time);
}