diff options
author | Jay Berkenbilt <ejb@ql.org> | 2021-04-18 00:12:55 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2021-04-18 00:12:55 +0200 |
commit | 36c7c208191a0fd34cf48bdfb4af66b4ab0ec594 (patch) | |
tree | b9a0afe891c01222e1c844e1d3bb0b85fc724f12 /libqpdf | |
parent | 8971443e4680fc1c0babe56da58cc9070a9dae2e (diff) | |
download | qpdf-36c7c208191a0fd34cf48bdfb4af66b4ab0ec594.tar.zst |
Fix timezone portability issue (fixes #515)
Diffstat (limited to 'libqpdf')
-rw-r--r-- | libqpdf/QUtil.cc | 13 | ||||
-rw-r--r-- | libqpdf/qpdf/qpdf-config.h.in | 6 |
2 files changed, 18 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 } diff --git a/libqpdf/qpdf/qpdf-config.h.in b/libqpdf/qpdf/qpdf-config.h.in index 78ebc86d..d0e42fbd 100644 --- a/libqpdf/qpdf/qpdf-config.h.in +++ b/libqpdf/qpdf/qpdf-config.h.in @@ -12,6 +12,9 @@ /* Define to 1 if you have the <dlfcn.h> header file. */ #undef HAVE_DLFCN_H +/* Whether extern long timezone is available */ +#undef HAVE_EXTERN_LONG_TIMEZONE + /* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ #undef HAVE_FSEEKO @@ -51,6 +54,9 @@ /* Define to 1 if you have the <sys/types.h> header file. */ #undef HAVE_SYS_TYPES_H +/* Whether struct tm has tm_gmtoff */ +#undef HAVE_TM_GMTOFF + /* Define to 1 if you have the <unistd.h> header file. */ #undef HAVE_UNISTD_H |