From a70e19a51423b855b9da8d7f9ed40d396a534c67 Mon Sep 17 00:00:00 2001 From: rbuj Date: Mon, 20 Jan 2020 16:00:37 +0100 Subject: Fix year 2038 issue with signed 32-bit integers GTime is defined to always be a signed 32-bit integer, it will overflow in the year 2038. --- libdocument/ev-document-misc.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'libdocument/ev-document-misc.c') diff --git a/libdocument/ev-document-misc.c b/libdocument/ev-document-misc.c index e25b9ca6..80948936 100644 --- a/libdocument/ev-document-misc.c +++ b/libdocument/ev-document-misc.c @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -359,25 +360,17 @@ ev_document_misc_get_monitor_dpi (GdkMonitor *monitor) /* Returns a locale specific date and time representation */ gchar * -ev_document_misc_format_date (GTime utime) +ev_document_misc_format_date (gint64 utime) { - time_t time = (time_t) utime; - char s[256]; - const char fmt_hack[] = "%c"; - size_t len; -#ifdef HAVE_LOCALTIME_R - struct tm t; - if (time == 0 || !localtime_r (&time, &t)) return NULL; - len = strftime (s, sizeof (s), fmt_hack, &t); -#else - struct tm *t; - if (time == 0 || !(t = localtime (&time)) ) return NULL; - len = strftime (s, sizeof (s), fmt_hack, t); -#endif - - if (len == 0 || s[0] == '\0') return NULL; - - return g_locale_to_utf8 (s, -1, NULL, NULL, NULL); + GDateTime *date_time; + gchar *result = NULL; + + date_time = g_date_time_new_from_unix_local (utime); + if (date_time != NULL) { + result = g_date_time_format (date_time, "%c"); + g_date_time_unref (date_time); + } + return result; } void -- cgit v1.2.1