summaryrefslogtreecommitdiffstats
path: root/core/trip.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-06-28 07:33:51 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-06-28 20:13:49 +0900
commit9e1d83ca562bcd33ae887a42df4fc5edf323f007 (patch)
tree2332e01e46d5a358bb1a25616e2378e7533c05d2 /core/trip.c
parent230f3846fa77d1b58195e71489fba145bcd1e0b7 (diff)
downloadsubsurface-9e1d83ca562bcd33ae887a42df4fc5edf323f007.tar.gz
Import: use TRIP_THRESHOLD when checking for trip-overlap
When checking for trip-overlap on import, only really overlapping trips have been considered, i.e. when dives had overlapping times. Instead use the TRIP_THRESHOLD so that on download dives are added to the same trip if in a two-days time frame. Reported-by: Miika Turkia <miika.turkia@gmail.com> Reported-by: Dirk Hohndel <dirk@hohndel.org> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/trip.c')
-rw-r--r--core/trip.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/core/trip.c b/core/trip.c
index 446f153eb..bc9b1b5a9 100644
--- a/core/trip.c
+++ b/core/trip.c
@@ -192,6 +192,19 @@ dive_trip_t *get_trip_for_new_dive(struct dive *new_dive, bool *allocated)
return trip;
}
+/* Check if two trips overlap time-wise up to trip threshold. */
+bool trips_overlap(const struct dive_trip *t1, const struct dive_trip *t2)
+{
+ /* First, handle the empty-trip cases. */
+ if (t1->dives.nr == 0 || t2->dives.nr == 0)
+ return 0;
+
+ if (trip_date(t1) < trip_date(t2))
+ return trip_enddate(t1) + TRIP_THRESHOLD >= trip_date(t2);
+ else
+ return trip_enddate(t2) + TRIP_THRESHOLD >= trip_date(t1);
+}
+
/*
* Collect dives for auto-grouping. Pass in first dive which should be checked.
* Returns range of dives that should be autogrouped and trip it should be