summaryrefslogtreecommitdiffstats
path: root/core/divelist.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-11-11 13:09:51 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-11-18 16:50:09 -0800
commit64e6e435f82801f4f440ef5b1caf58a91a7c9929 (patch)
tree0f2c662daab035463de05c1564af7026c7edbd7e /core/divelist.c
parent431b2bb84542d4f45952b48aa91231f979762e00 (diff)
downloadsubsurface-64e6e435f82801f4f440ef5b1caf58a91a7c9929.tar.gz
Core: remove "when" field of struct dive_trip
The when field gives the time of the first dive. Instead of keeping this field in sync, replace it by a function that determines the time of the first dive. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/divelist.c')
-rw-r--r--core/divelist.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/core/divelist.c b/core/divelist.c
index 0fea7594e..7f946b039 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -739,7 +739,7 @@ void dump_trip_list(void)
for (trip = dive_trip_list; trip; trip = trip->next) {
struct tm tm;
- utc_mkdate(trip->when, &tm);
+ utc_mkdate(trip_date(trip), &tm);
if (trip->when < last_time)
printf("\n\ndive_trip_list OUT OF ORDER!!!\n\n\n");
printf("%s trip %d to \"%s\" on %04u-%02u-%02u %02u:%02u:%02u (%d dives - %p)\n",
@@ -805,9 +805,12 @@ static void delete_trip(dive_trip_t *trip)
free_trip(trip);
}
-void find_new_trip_start_time(dive_trip_t *trip)
+
+timestamp_t trip_date(const struct dive_trip *trip)
{
- trip->when = trip->dives.nr > 0 ? trip->dives.dives[0]->when : 0;
+ if (!trip || trip->dives.nr == 0)
+ return 0;
+ return trip->dives.dives[0]->when;
}
/* check if we have a trip right before / after this dive */
@@ -876,8 +879,6 @@ struct dive_trip *unregister_dive_from_trip(struct dive *dive, short was_autogen
dive->tripflag = TF_NONE;
else
dive->tripflag = NO_TRIP;
- if (trip->dives.nr > 0 && trip->when == dive->when)
- find_new_trip_start_time(trip);
return trip;
}
@@ -908,7 +909,6 @@ dive_trip_t *create_trip_from_dive(struct dive *dive)
dive_trip_t *trip;
trip = alloc_trip();
- trip->when = dive->when;
trip->location = copy_string(get_dive_location(dive));
return trip;
@@ -1345,7 +1345,6 @@ dive_trip_t *combine_trips_create(struct dive_trip *trip_a, struct dive_trip *tr
dive_trip_t *trip;
trip = alloc_trip();
- trip->when = trip_a->when;
trip->location = copy_non_empty_string(trip_a->location, trip_b->location);
trip->notes = copy_non_empty_string(trip_a->notes, trip_b->notes);
@@ -1726,9 +1725,9 @@ static int comp_dives(const struct dive *a, const struct dive *b)
return -1;
if (!a->divetrip)
return 1;
- if (a->divetrip->when < b->divetrip->when)
+ if (trip_date(a->divetrip) < trip_date(b->divetrip))
return -1;
- if (a->divetrip->when > b->divetrip->when)
+ if (trip_date(a->divetrip) > trip_date(b->divetrip))
return 1;
}
if (a->id < b->id)