mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-01 00:13:24 +00:00
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>
This commit is contained in:
parent
2fb7aa1172
commit
3b7d68c091
1 changed files with 14 additions and 2 deletions
16
planner.c
16
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);
|
||||
|
|
Loading…
Add table
Reference in a new issue