From 28b4f8a7186a4e3d41714d483686e1d946109594 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Wed, 24 Feb 2016 21:10:08 +1030 Subject: [PATCH 3/4] pdfinfo: convert dates to local time zone --- utils/pdfinfo.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc index 18221c2..6194530 100644 --- a/utils/pdfinfo.cc +++ b/utils/pdfinfo.cc @@ -469,6 +469,7 @@ static void printInfoDate(Dict *infoDict, const char *key, const char *text) { int year, mon, day, hour, min, sec, tz_hour, tz_minute; char tz; struct tm tmStruct; + time_t time; char buf[256]; if (infoDict->lookup(key, &obj)->isString()) { @@ -486,8 +487,14 @@ static void printInfoDate(Dict *infoDict, const char *key, const char *text) { tmStruct.tm_yday = -1; tmStruct.tm_isdst = -1; // compute the tm_wday and tm_yday fields - if (mktime(&tmStruct) != (time_t)-1 && - strftime(buf, sizeof(buf), "%c", &tmStruct)) { + time = timegm(&tmStruct); + if (time != (time_t)-1) { + int offset = (tz_hour*60 + tz_minute)*60; + if (tz == '-') + offset *= -1; + time -= offset; + localtime_r(&time, &tmStruct); + strftime(buf, sizeof(buf), "%c %Z", &tmStruct); fputs(buf, stdout); } else { fputs(s, stdout); -- 2.1.4