Skip to content

Fix getTimezoneOffset() when tm_gmtoff is not available #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ xoption(BUILD_STATIC_QJS_EXE "Build a static qjs executable" OFF)
xoption(CONFIG_ASAN "Enable AddressSanitizer (ASan)" OFF)
xoption(CONFIG_MSAN "Enable MemorySanitizer (MSan)" OFF)
xoption(CONFIG_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan)" OFF)
xoption(HAVE_TM_GMTOFF "Enable when `tm_gmtoff` exists on `struct tm`" ON)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we were going to drop this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an explicit option to disable, defaults to ON.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but if you just copy the C files over to a project with an existing build system it won't work.

Ideally updating from QuickJS to our NG is a simple as overwriting the files, without the need to add extra build time flags.


if(CONFIG_ASAN)
message(STATUS "Building with ASan")
Expand Down
16 changes: 16 additions & 0 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
#define CONFIG_PRINTF_RNDN
#endif

#if defined(__NEWLIB__)
/* undefine if `struct tm` does not contain `tm_gmtoff` property */
/* this can also be configured through `cmake -DHAVE_TM_GMTOFF=OFF */
#undef HAVE_TM_GMTOFF
#endif

/* dump object free */
//#define DUMP_FREE
//#define DUMP_CLOSURE
Expand Down Expand Up @@ -40524,7 +40530,17 @@ static int getTimezoneOffset(int64_t time) {
}
ti = time;
localtime_r(&ti, &tm);
#ifdef HAVE_TM_GMTOFF
return -tm.tm_gmtoff / 60;
#else
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;
#endif /* HAVE_TM_GMTOFF */
#endif
}

Expand Down