From 7713c7e607b11c0828decdbf35d910280153f880 Mon Sep 17 00:00:00 2001 From: Stefan Fuchs Date: Sat, 30 Sep 2017 18:00:34 +0200 Subject: Use helper function dive_endtime() where apropriate Calculating dive.when + dive.duration doesn't always give the correct endtime of a dive especially when a dive has surface interval(s) in the middle. Using the helper function dive_endtime() fixes this issue. Signed-off-by: Stefan Fuchs --- desktop-widgets/subsurfacewebservices.cpp | 9 +++++---- desktop-widgets/tab-widgets/TabDiveInformation.cpp | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/subsurfacewebservices.cpp b/desktop-widgets/subsurfacewebservices.cpp index 371a8475a..6c982d27f 100644 --- a/desktop-widgets/subsurfacewebservices.cpp +++ b/desktop-widgets/subsurfacewebservices.cpp @@ -12,6 +12,7 @@ #include "core/subsurface-qt/SettingsObjectWrapper.h" #include #include "core/cloudstorage.h" +#include "core/dive.h" #include #include @@ -70,7 +71,7 @@ static bool merge_locations_into_dives(void) qDebug() << "processing gpsfix @" << get_dive_date_string(gpsfix->when) << "which is withing six hours of dive from" << get_dive_date_string(dive->when) << "until" << - get_dive_date_string(dive->when + dive->duration.seconds); + get_dive_date_string(dive_endtime(dive)); /* * If position is fixed during dive. This is the good one. * Asign and mark position, and end gps_location loop @@ -106,7 +107,7 @@ static bool merge_locations_into_dives(void) if (verbose) qDebug() << "which is closer to the start of the dive, do continue with that"; continue; - } else if (gpsfix->when > dive->when + dive->duration.seconds) { + } else if (gpsfix->when > dive_endtime(dive)) { if (verbose) qDebug() << "which is even later after the end of the dive, so pick the previous one"; copy_gps_location(gpsfix, dive); @@ -115,7 +116,7 @@ static bool merge_locations_into_dives(void) break; } else { /* ok, gpsfix is before, nextgpsfix is after */ - if (dive->when - gpsfix->when <= nextgpsfix->when - (dive->when + dive->duration.seconds)) { + if (dive->when - gpsfix->when <= nextgpsfix->when - dive_endtime(dive)) { if (verbose) qDebug() << "pick the one before as it's closer to the start"; copy_gps_location(gpsfix, dive); @@ -147,7 +148,7 @@ static bool merge_locations_into_dives(void) /* If position is out of SAME_GROUP range and in the future, mark position for * next dive iteration and end the gps_location loop */ - if (gpsfix->when >= dive->when + dive->duration.seconds + SAME_GROUP) { + if (gpsfix->when >= dive_endtime(dive) + SAME_GROUP) { tracer = j; break; } diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.cpp b/desktop-widgets/tab-widgets/TabDiveInformation.cpp index 419e73739..ae3998ed8 100644 --- a/desktop-widgets/tab-widgets/TabDiveInformation.cpp +++ b/desktop-widgets/tab-widgets/TabDiveInformation.cpp @@ -6,6 +6,7 @@ #include #include #include +#include TabDiveInformation::TabDiveInformation(QWidget *parent) : TabBase(parent), ui(new Ui::TabDiveInformation()) { @@ -81,7 +82,7 @@ void TabDiveInformation::updateData() process_all_dives(&displayed_dive, &prevd); if (prevd) - ui->surfaceIntervalText->setText(get_dive_surfint_string(displayed_dive.when - (prevd->when + prevd->duration.seconds), tr("d"), tr("h"), tr("min"))); + ui->surfaceIntervalText->setText(get_dive_surfint_string(displayed_dive.when - (dive_endtime(prevd)), tr("d"), tr("h"), tr("min"))); else ui->surfaceIntervalText->clear(); -- cgit v1.2.3-70-g09d2