aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-15 09:14:22 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-15 10:09:42 -0800
commit3b7d68c091ae45b5de0aa2293afa92381111a76b (patch)
tree080691b29e4e44e889701a6d13870f07195f6870
parent2fb7aa1172930cbedb5ea9b24c6f2c98f40a7ff1 (diff)
downloadsubsurface-3b7d68c091ae45b5de0aa2293afa92381111a76b.tar.gz
Correct the start time of planned dives
Subsurface follows the lead of most divecomputers to use times without timezone - so all times are implicitly assumed to be local time of the dive location; so in order to give the current time in that way we actually need to add the timezone offset. Instead of relying on OS specific members of struct tm we use the glib timezone functions to get the timezone offset for us. Of course, the function used to do this is only in glib 2.26 or newer, which once again means that Debian stable won't be supported. But since that doesn't build other parts of Subsurface, either, I think I'll live with that. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--planner.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/planner.c b/planner.c
index 4389aac50..bf6bd5439 100644
--- a/planner.c
+++ b/planner.c
@@ -806,6 +806,17 @@ static gboolean duration_focus_out_cb(GtkWidget *entry, GdkEvent * event, gpoint
return FALSE;
}
+/* Subsurface follows the lead of most divecomputers to use times
+ * without timezone - so all times are implicitly assumed to be
+ * local time of the dive location; so in order to give the current
+ * time in that way we actually need to add the timezone offset */
+static timestamp_t current_time_notz(void)
+{
+ timestamp_t now = time(NULL);
+ int offset = g_time_zone_get_offset(g_time_zone_new_local(), 1);
+ return now + offset;
+}
+
static gboolean starttime_focus_out_cb(GtkWidget *entry, GdkEvent * event, gpointer data)
{
const char *starttimetext;
@@ -814,7 +825,7 @@ 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 = time(NULL) + starttime;
+ diveplan.when = current_time_notz() + starttime;
show_planned_dive();
} else {
/* we need to instead change the color of the input field or something */
@@ -905,6 +916,7 @@ static void add_waypoint_cb(GtkButton *button, gpointer _data)
}
}
+/* set up the dialog where the user can input their dive plan */
void input_plan()
{
GtkWidget *planner, *content, *vbox, *hbox, *outervbox, *add_row, *deltat, *label, *surfpres;
@@ -949,7 +961,7 @@ void input_plan()
gtk_entry_set_text(GTK_ENTRY(surfpres), pressurebuf);
gtk_widget_add_events(surfpres, GDK_FOCUS_CHANGE_MASK);
g_signal_connect(surfpres, "focus-out-event", G_CALLBACK(surfpres_focus_out_cb), NULL);
- diveplan.when = time(NULL) + 3600;
+ diveplan.when = current_time_notz() + 3600;
diveplan.surface_pressure = SURFACE_PRESSURE;
nr_waypoints = 4;
add_waypoint_widgets(vbox, 0);