summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Stefan Fuchs <sfuchs@gmx.de>2017-09-30 18:00:34 +0200
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2017-10-01 23:55:37 +0300
commit7713c7e607b11c0828decdbf35d910280153f880 (patch)
tree8e08d80032ba7cdcaa344042da7e220f217b75c5 /core
parent325c4459ade70f626d6a39fecfb9e0c27f0c5cee (diff)
downloadsubsurface-7713c7e607b11c0828decdbf35d910280153f880.tar.gz
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 <sfuchs@gmx.de>
Diffstat (limited to 'core')
-rw-r--r--core/divelist.c11
-rw-r--r--core/gpslocation.cpp8
2 files changed, 9 insertions, 10 deletions
diff --git a/core/divelist.c b/core/divelist.c
index 60b398539..d079b11bf 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -229,7 +229,7 @@ static int calculate_cns(struct dive *dive)
if (divenr) {
prev_dive = get_dive(divenr - 1);
if (prev_dive) {
- endtime = prev_dive->when + prev_dive->duration.seconds;
+ endtime = dive_endtime(prev_dive);
if (dive->when < (endtime + 3600 * 12)) {
cns = calculate_cns(prev_dive);
cns = cns * 1 / pow(2, (dive->when - endtime) / (90.0 * 60.0));
@@ -395,13 +395,12 @@ unsigned int init_decompression(struct dive *dive)
* for how far back we need to go */
if (dive->divetrip && pdive->divetrip != dive->divetrip)
continue;
- if (!pdive || pdive->when >= when || pdive->when + pdive->duration.seconds + 48 * 60 * 60 < when)
+ if (!pdive || pdive->when >= when || dive_endtime(pdive) + 48 * 60 * 60 < when)
break;
/* For simultaneous dives, only consider the first */
if (pdive->when == laststart)
continue;
- when = pdive->when;
- lasttime = when + pdive->duration.seconds;
+ lasttime = dive_endtime(pdive);
}
while (++i < (divenr >= 0 ? divenr : dive_table.nr)) {
struct dive *pdive = get_dive(i);
@@ -421,7 +420,7 @@ unsigned int init_decompression(struct dive *dive)
}
if (pdive->when > lasttime) {
surface_time = pdive->when - lasttime;
- lasttime = pdive->when + pdive->duration.seconds;
+ lasttime = dive_endtime(pdive);
add_segment(surface_pressure, &air, surface_time, 0, dive, prefs.decosac);
#if DECO_CALC_DEBUG & 2
printf("after surface intervall of %d:%02u\n", FRACTION(surface_time, 60));
@@ -1136,7 +1135,7 @@ void process_dives(bool is_imported, bool prefer_imported)
/* only try to merge overlapping dives - or if one of the dives has
* zero duration (that might be a gps marker from the webservice) */
if (prev->duration.seconds && dive->duration.seconds &&
- prev->when + prev->duration.seconds < dive->when)
+ dive_endtime(prev) < dive->when)
continue;
merged = try_to_merge(prev, dive, prefer_imported);
diff --git a/core/gpslocation.cpp b/core/gpslocation.cpp
index a823a9124..22525ca3d 100644
--- a/core/gpslocation.cpp
+++ b/core/gpslocation.cpp
@@ -275,7 +275,7 @@ bool GpsLocation::applyLocations()
qDebug() << "processing gpsFix @" << get_dive_date_string(gpsTable[j].when) <<
"which is withing six hours of dive from" <<
get_dive_date_string(d->when) << "until" <<
- get_dive_date_string(d->when + d->duration.seconds);
+ get_dive_date_string(dive_endtime(d));
/*
* If position is fixed during dive. This is the good one.
* Asign and mark position, and end gps_location loop
@@ -310,7 +310,7 @@ bool GpsLocation::applyLocations()
if (verbose)
qDebug() << "which is closer to the start of the dive, do continue with that";
continue;
- } else if (gpsTable[j].when > d->when + d->duration.seconds) {
+ } else if (gpsTable[j].when > dive_endtime(d)) {
if (verbose)
qDebug() << "which is even later after the end of the dive, so pick the previous one";
copy_gps_location(gpsTable[j], d);
@@ -319,7 +319,7 @@ bool GpsLocation::applyLocations()
break;
} else {
/* ok, gpsFix is before, nextgpsFix is after */
- if (d->when - gpsTable[j].when <= gpsTable[j+1].when - (d->when + d->duration.seconds)) {
+ if (d->when - gpsTable[j].when <= gpsTable[j+1].when - dive_endtime(d)) {
if (verbose)
qDebug() << "pick the one before as it's closer to the start";
copy_gps_location(gpsTable[j], d);
@@ -351,7 +351,7 @@ bool GpsLocation::applyLocations()
/* 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 (gpsTable[j].when >= d->when + d->duration.seconds + SAME_GROUP) {
+ if (gpsTable[j].when >= dive_endtime(d) + SAME_GROUP) {
last = j;
break;
}