aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf/QUtil.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2021-04-18 00:12:55 +0200
committerJay Berkenbilt <ejb@ql.org>2021-04-18 00:12:55 +0200
commit36c7c208191a0fd34cf48bdfb4af66b4ab0ec594 (patch)
treeb9a0afe891c01222e1c844e1d3bb0b85fc724f12 /libqpdf/QUtil.cc
parent8971443e4680fc1c0babe56da58cc9070a9dae2e (diff)
downloadqpdf-36c7c208191a0fd34cf48bdfb4af66b4ab0ec594.tar.zst
Fix timezone portability issue (fixes #515)
Diffstat (limited to 'libqpdf/QUtil.cc')
-rw-r--r--libqpdf/QUtil.cc13
1 files changed, 12 insertions, 1 deletions
diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc
index 17b163f5..f45468a0 100644
--- a/libqpdf/QUtil.cc
+++ b/libqpdf/QUtil.cc
@@ -889,6 +889,7 @@ QUtil::get_current_qpdf_time()
static_cast<int>(ltime.wHour),
static_cast<int>(ltime.wMinute),
static_cast<int>(ltime.wSecond),
+ // tzinfo.Bias is minutes before UTC
static_cast<int>(tzinfo.Bias));
#else
struct tm ltime;
@@ -899,13 +900,23 @@ QUtil::get_current_qpdf_time()
#else
ltime = *localtime(&now);
#endif
+#if HAVE_TM_GMTOFF
+ // tm_gmtoff is seconds after UTC
+ int tzoff = -static_cast<int>(ltime.tm_gmtoff / 60);
+#elif HAVE_EXTERN_LONG_TIMEZONE
+ // timezone is seconds before UTC, not adjusted for daylight saving time
+ int tzoff = static_cast<int>(timezone / 60);
+#else
+ // Don't know how to get timezone on this platform
+ int tzoff = 0;
+#endif
return QPDFTime(static_cast<int>(ltime.tm_year + 1900),
static_cast<int>(ltime.tm_mon + 1),
static_cast<int>(ltime.tm_mday),
static_cast<int>(ltime.tm_hour),
static_cast<int>(ltime.tm_min),
static_cast<int>(ltime.tm_sec),
- static_cast<int>(timezone / 60));
+ tzoff);
#endif
}