From 1991ae6aa9714fa63f09352d4566bb79a4c87b0e Mon Sep 17 00:00:00 2001 From: Jakub Kucharski Date: Sun, 7 Feb 2016 13:30:55 +0100 Subject: [PATCH] glib: return UTC dates --- glib/poppler-date.cc | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/glib/poppler-date.cc b/glib/poppler-date.cc index e3141c1..5312843 100644 --- a/glib/poppler-date.cc +++ b/glib/poppler-date.cc @@ -1,6 +1,7 @@ /* poppler-date.cc: glib interface to poppler * * Copyright (C) 2009 Carlos Garcia Campos + * Copyright (C) 2016 Jakub Kucharski * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,9 +19,37 @@ */ #include +#include #include "poppler-date.h" +static time_t +utc_mktime (struct tm *tm) +{ + time_t ret; + + char *tz = getenv("TZ"); + if (tz) { + tz = strdup(tz); + } + + setenv("TZ", "", 1); + tzset(); + + ret = mktime(tm); + + if (tz) { + setenv("TZ", tz, 1); + free(tz); + } else { + unsetenv("TZ"); + } + + tzset(); + + return ret; +} + /** * poppler_date_parse: * @date: string to parse @@ -58,10 +87,16 @@ poppler_date_parse (const gchar *date, time.tm_isdst = -1; /* 0 = DST off, 1 = DST on, -1 = don't know */ /* compute tm_wday and tm_yday and check date */ - retval = mktime (&time); + retval = utc_mktime (&time); if (retval == (time_t) - 1) return FALSE; - + + gint64 offset = 60*60*tz_hour + 60*tz_minute; + if (tz == '-') { + offset *= -1; + } + retval -= offset; + *timet = retval; return TRUE; -- 2.7.0