From 440fc1b96bf1b33a23af616e416b2483d51a34b2 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Sun, 24 Dec 2023 00:34:14 -0800 Subject: [PATCH] Fix `getTimezoneOffset()` when `tm_gmtoff` is not available (#224) --- quickjs.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/quickjs.c b/quickjs.c index 7be7abb..4e4a5cd 100644 --- a/quickjs.c +++ b/quickjs.c @@ -60,6 +60,10 @@ #define CONFIG_PRINTF_RNDN #endif +#if defined(__NEWLIB__) +#define NO_TM_GMTOFF +#endif + /* dump object free */ //#define DUMP_FREE //#define DUMP_CLOSURE @@ -40685,7 +40689,17 @@ static int getTimezoneOffset(int64_t time) { } ti = time; localtime_r(&ti, &tm); +#ifdef NO_TM_GMTOFF + struct tm gmt; + gmtime_r(&ti, &gmt); + + /* disable DST adjustment on the local tm struct */ + tm.tm_isdst = 0; + + return difftime(mktime(&gmt), mktime(&tm)) / 60; +#else return -tm.tm_gmtoff / 60; +#endif /* NO_TM_GMTOFF */ #endif }