summaryrefslogtreecommitdiffstats
path: root/planner.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-31 23:47:26 +1100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-31 23:50:35 +1100
commitaa55bda94433ba22df2f4a4bff1c3f78f6fd8406 (patch)
tree53a035e679127c9e38c35d81930c3c9f995eb321 /planner.c
parentde7d5b2d5b441b3c8efa29a6b64a7685ef835768 (diff)
downloadsubsurface-aa55bda94433ba22df2f4a4bff1c3f78f6fd8406.tar.gz
Don't allow to plan dives out of order
The planned dive always has to be the last dive in the dive list. To make sure of that we interpret the relative start time to be relative to either the current time or the end of the last dive, whichever is later. This fixes a bug where we would delete the wrong dive and get our data structures confused by planning multiple dives out of order. Reported-by: Sergey Starosek <sergey.starosek@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'planner.c')
-rw-r--r--planner.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/planner.c b/planner.c
index a3936926b..8a2d71990 100644
--- a/planner.c
+++ b/planner.c
@@ -1053,8 +1053,15 @@ static gboolean starttime_focus_out_cb(GtkWidget *entry, GdkEvent * event, gpoin
starttimetext = gtk_entry_get_text(GTK_ENTRY(entry));
if (validate_time(starttimetext, &starttime, &is_rel)) {
- /* we alway make this relative for now */
- diveplan.when = current_time_notz() + starttime;
+ /* we alway make this relative - either from the current time or from the
+ * end of the last dive, whichever is later */
+ timestamp_t cur = current_time_notz();
+ if (dive_table.nr) {
+ struct dive *last_dive = get_dive(dive_table.nr - 1);
+ if (last_dive && last_dive->when + last_dive->dc.duration.seconds > cur)
+ cur = last_dive->when + last_dive->dc.duration.seconds;
+ }
+ diveplan.when = cur + starttime;
show_planned_dive();
} else {
/* we need to instead change the color of the input field or something */