From dce08deb34939eaed349d315777214c3181c1a8d Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 19 Sep 2012 17:35:52 -0700 Subject: Use a 64-bit 'timestamp_t' for all timestamps, rather than 'time_t' This makes the time type unambiguous, and we can use G_TYPE_INT64 for it in the divelist too. It also implements a portable (and thread-safe) "utc_mkdate()" function that acts kind of like gmtime_r(), but using the 64-bit timestamp_t. It matches our original "utc_mktime()". Signed-off-by: Linus Torvalds --- info.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'info.c') diff --git a/info.c b/info.c index ad482f11d..16149cb02 100644 --- a/info.c +++ b/info.c @@ -99,13 +99,15 @@ static char *get_combo_box_entry_text(GtkComboBoxEntry *combo_box, char **textp, static int divename(char *buf, size_t size, struct dive *dive) { - struct tm *tm = gmtime(&dive->when); + struct tm tm; + + utc_mkdate(dive->when, &tm); return snprintf(buf, size, "Dive #%d - %s %02d/%02d/%04d at %d:%02d", dive->number, - weekday(tm->tm_wday), - tm->tm_mon+1, tm->tm_mday, - tm->tm_year+1900, - tm->tm_hour, tm->tm_min); + weekday(tm.tm_wday), + tm.tm_mon+1, tm.tm_mday, + tm.tm_year+1900, + tm.tm_hour, tm.tm_min); } void show_dive_info(struct dive *dive) @@ -681,7 +683,7 @@ static GtkWidget *frame_box(GtkWidget *vbox, const char *fmt, ...) } /* Fixme - should do at least depths too - a dive without a depth is kind of pointless */ -static time_t dive_time_widget(struct dive *dive) +static timestamp_t dive_time_widget(struct dive *dive) { GtkWidget *dialog; GtkWidget *cal, *hbox, *vbox, *box; @@ -719,12 +721,13 @@ static time_t dive_time_widget(struct dive *dive) * we'll just take the current time. */ if (amount_selected == 1) { - time_t when = current_dive->when; + timestamp_t when = current_dive->when; when += current_dive->duration.seconds; when += 60*60; - time = gmtime(&when); + utc_mkdate(when, &tm); + time = &tm; } else { - time_t now; + timestamp_t now; struct timeval tv; gettimeofday(&tv, NULL); now = tv.tv_sec; -- cgit v1.2.3-70-g09d2 From 4f920b71aae7ecb1470888b95c472c1f794486bc Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Thu, 20 Sep 2012 10:53:45 -0700 Subject: dive-time widget: fix incorrect use of timestamp_t I did a global search-and-replace to make all "time_t" users use the internal subsurface 64-bit "timestamp_t" type instead, but we have one case that still uses the system time functions: the use of "localtime()" in the dive_time_widget(). Everywhere else we always just use UTC for all our time handling, and we don't really ever care about the local timezone etc. However, for the dive time widget, we initialize the calendar widget to the current time, which obviously does want to take the local timezone into account, so there we end up using the whole system time handling code. So that one should continue to use time_t, even if it might have the year-2038 problem. We also don't care about the fact that it's not thread-safe, since this is just initializing the widget which definitely doesn't happen threaded. Signed-off-by: Linus Torvalds --- info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'info.c') diff --git a/info.c b/info.c index 16149cb02..40e0af278 100644 --- a/info.c +++ b/info.c @@ -727,7 +727,7 @@ static timestamp_t dive_time_widget(struct dive *dive) utc_mkdate(when, &tm); time = &tm; } else { - timestamp_t now; + time_t now; struct timeval tv; gettimeofday(&tv, NULL); now = tv.tv_sec; -- cgit v1.2.3-70-g09d2