Include timezone in timeToDateString()
diff --git a/poppler/DateInfo.cc b/poppler/DateInfo.cc
index 67be91c..4cbc095 100644
--- a/poppler/DateInfo.cc
+++ b/poppler/DateInfo.cc
@@ -6,7 +6,7 @@
 // Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
 // Copyright (C) 2015 André Guerreiro <aguerreiro1985@gmail.com>
 // Copyright (C) 2015 André Esser <bepandre@hotmail.com>
-// Copyright (C) 2016 Adrian Johnson <ajohnson@redneon.com>
+// Copyright (C) 2016, 2018 Adrian Johnson <ajohnson@redneon.com>
 //
 // To see a description of the changes please see the Changelog file that
 // came with your tarball or type make ChangeLog if you are building from git
@@ -76,42 +76,29 @@
    return false;
 }
 
-// Convert time to PDF date string
-GooString *timeToDateString(time_t *timet) {
-  GooString *dateString;
-  char s[5];
-  struct tm *gt;
-  size_t len;
-  time_t timep = timet ? *timet : time(nullptr);
-  struct tm t;
+GooString *timeToDateString(time_t *timeA)
+{
+  const time_t timet = timeA ? *timeA : time(nullptr);
 
-  gt = gmtime_r (&timep, &t);
+  struct tm localtime_tm;
+  localtime_r (&timet, &localtime_tm);
 
-  dateString = new GooString ("D:");
+  char buf[50];
+  strftime (buf, sizeof(buf), "D:%Y%m%d%H%M%S", &localtime_tm);
+  GooString *dateString = new GooString(buf);
 
-  /* Year YYYY */
-  len = strftime (s, sizeof(s), "%Y", gt);
-  dateString->append (s, len);
-
-  /* Month MM */
-  len = strftime (s, sizeof(s), "%m", gt);
-  dateString->append (s, len);
-
-  /* Day DD */
-  len = strftime (s, sizeof(s), "%d", gt);
-  dateString->append (s, len);
-
-  /* Hour HH */
-  len = strftime (s, sizeof(s), "%H", gt);
-  dateString->append (s, len);
-
-  /* Minute mm */
-  len = strftime (s, sizeof(s), "%M", gt);
-  dateString->append (s, len);
-
-  /* Second SS */
-  len = strftime (s, sizeof(s), "%S", gt);
-  dateString->append (s, len);
+  // strftime "%z" does not work on windows (it prints zone name, not offset)
+  // calculate time zone offset by comparing local and gmtime time_t value for same
+  // time.
+  const time_t timeg = timegm(&localtime_tm);
+  const time_t offset = difftime(timeg, timet); // find time zone offset in seconds
+  if (offset > 0) {
+    dateString->appendf("+{0:02d}'{1:02d}", offset/3600, (offset%3600)/60);
+  } else if (offset < 0) {
+    dateString->appendf("-{0:02d}'{1:02d}", -offset/3600, (-offset%3600)/60);
+  } else {
+    dateString->append("Z");
+  }
 
   return dateString;
 }
diff --git a/poppler/DateInfo.h b/poppler/DateInfo.h
index 4fb03c3..d726b31 100644
--- a/poppler/DateInfo.h
+++ b/poppler/DateInfo.h
@@ -31,6 +31,7 @@
 
 /* Converts the time_t into a PDF Date format string.
  * If timet is NULL, current time is used.
+ * Returns new GooString. Free with delete.
  */
 GooString *timeToDateString(time_t *timet);