From 9e1d83ca562bcd33ae887a42df4fc5edf323f007 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 28 Jun 2019 07:33:51 +0200 Subject: [PATCH] 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 Reported-by: Dirk Hohndel Signed-off-by: Berthold Stoeger --- core/divelist.c | 13 ------------- core/trip.c | 13 +++++++++++++ core/trip.h | 1 + 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/core/divelist.c b/core/divelist.c index 62e79ac59..292e90c73 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -1032,19 +1032,6 @@ static bool try_to_merge_into(struct dive *dive_to_add, int idx, struct dive_tab return true; } -/* Check if two trips overlap time-wise. */ -static 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_date(t2); - else - return trip_enddate(t2) >= trip_date(t1); -} - /* Check if a dive is ranked after the last dive of the global dive list */ static bool dive_is_after_last(struct dive *d) { 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 diff --git a/core/trip.h b/core/trip.h index 3b7fec44d..2ca2791cd 100644 --- a/core/trip.h +++ b/core/trip.h @@ -42,6 +42,7 @@ extern dive_trip_t *create_trip_from_dive(struct dive *dive); extern dive_trip_t *create_and_hookup_trip_from_dive(struct dive *dive, struct trip_table *trip_table_arg); extern dive_trip_t *get_dives_to_autogroup(struct dive_table *table, int start, int *from, int *to, bool *allocated); extern dive_trip_t *get_trip_for_new_dive(struct dive *new_dive, bool *allocated); +extern bool trips_overlap(const struct dive_trip *t1, const struct dive_trip *t2); extern void select_dives_in_trip(struct dive_trip *trip); extern void deselect_dives_in_trip(struct dive_trip *trip);