From 36c7c208191a0fd34cf48bdfb4af66b4ab0ec594 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 17 Apr 2021 18:12:55 -0400 Subject: Fix timezone portability issue (fixes #515) --- libqpdf/QUtil.cc | 13 ++++++++++++- libqpdf/qpdf/qpdf-config.h.in | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'libqpdf') 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(ltime.wHour), static_cast(ltime.wMinute), static_cast(ltime.wSecond), + // tzinfo.Bias is minutes before UTC static_cast(tzinfo.Bias)); #else struct tm ltime; @@ -898,6 +899,16 @@ QUtil::get_current_qpdf_time() localtime_r(&now, <ime); #else ltime = *localtime(&now); +#endif +#if HAVE_TM_GMTOFF + // tm_gmtoff is seconds after UTC + int tzoff = -static_cast(ltime.tm_gmtoff / 60); +#elif HAVE_EXTERN_LONG_TIMEZONE + // timezone is seconds before UTC, not adjusted for daylight saving time + int tzoff = static_cast(timezone / 60); +#else + // Don't know how to get timezone on this platform + int tzoff = 0; #endif return QPDFTime(static_cast(ltime.tm_year + 1900), static_cast(ltime.tm_mon + 1), @@ -905,7 +916,7 @@ QUtil::get_current_qpdf_time() static_cast(ltime.tm_hour), static_cast(ltime.tm_min), static_cast(ltime.tm_sec), - static_cast(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 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 header file. */ #undef HAVE_SYS_TYPES_H +/* Whether struct tm has tm_gmtoff */ +#undef HAVE_TM_GMTOFF + /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H -- cgit v1.2.3-54-g00ecf