Dive list: use dive trip time as additional sort criterion

The DiveTripModel places dives after trips in chronologically
ascending mode if the dive and the trip start at the same instant.
But in the core the sort order was undefined. This could lead
to a discrepancy. Therefore, implement the same sort-criterion
in the core code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-11-06 22:15:17 +01:00 committed by Dirk Hohndel
parent 7046c8b342
commit 49d1144336

View file

@ -1742,8 +1742,12 @@ void clear_table(struct dive_table *table)
* probably want to unify the models.
* After editing a key used in this sort-function, the order of
* the dives must be re-astablished.
* Currently, this does a lexicographic sort on the (start-time, id)
* tuple. "id" is a stable, strictly increasing unique number, that
* Currently, this does a lexicographic sort on the
* (start-time, trip-time, id) tuple.
* trip-time is defined such that dives that do not belong to
* a trip are sorted *after* dives that do. Thus, in the default
* chronologically-descending sort order, they are shown *before*.
* "id" is a stable, strictly increasing unique number, that
* is handed out when a dive is added to the system.
* We might also consider sorting by end-time and other criteria,
* but see the caveat above (editing means rearrangement of the dives).
@ -1754,6 +1758,16 @@ static int comp_dives(const struct dive *a, const struct dive *b)
return -1;
if (a->when > b->when)
return 1;
if (a->divetrip != b->divetrip) {
if (!b->divetrip)
return -1;
if (!a->divetrip)
return 1;
if (a->divetrip->when < b->divetrip->when)
return -1;
if (a->divetrip->when > b->divetrip->when)
return 1;
}
if (a->id < b->id)
return -1;
if (a->id > b->id)