From 84134e23e4615cb5bb8233c32d5739c675ea2dab Mon Sep 17 00:00:00 2001 From: Jakub Kucharski Date: Tue, 16 Feb 2016 19:44:53 +0100 Subject: [PATCH] cpp: return UTC dates --- cpp/poppler-private.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/cpp/poppler-private.cpp b/cpp/poppler-private.cpp index 3c3fe95..24b2062 100644 --- a/cpp/poppler-private.cpp +++ b/cpp/poppler-private.cpp @@ -116,6 +116,33 @@ GooString* detail::ustring_to_unicode_GooString(const ustring &str) return goo; } +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; +} + time_type detail::convert_date(const char *date) { int year, mon, day, hour, min, sec, tzHours, tzMins; @@ -136,5 +163,11 @@ time_type detail::convert_date(const char *date) time.tm_wday = -1; time.tm_yday = -1; time.tm_isdst = -1; - return mktime(&time); + + long offset = tzHours*60*60 + tzMins*60; + if (tz == '-') { + offset *= -1; + } + + return utc_mktime(&time) - offset; } -- 2.7.1