summaryrefslogtreecommitdiff
path: root/libdocument/ev-document-misc.c
diff options
context:
space:
mode:
authorrbuj <[email protected]>2020-01-20 16:00:37 +0100
committerraveit65 <[email protected]>2020-01-31 18:52:19 +0100
commita70e19a51423b855b9da8d7f9ed40d396a534c67 (patch)
tree1fe5414f810a3fadd3fbd88673987cad60d62aac /libdocument/ev-document-misc.c
parente388b7032dda81917b05583c306a4b9690dcaa46 (diff)
downloadatril-a70e19a51423b855b9da8d7f9ed40d396a534c67.tar.bz2
atril-a70e19a51423b855b9da8d7f9ed40d396a534c67.tar.xz
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.
Diffstat (limited to 'libdocument/ev-document-misc.c')
-rw-r--r--libdocument/ev-document-misc.c29
1 files changed, 11 insertions, 18 deletions
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 <string.h>
#include <math.h>
+#include <glib.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
@@ -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