Skip to content

Commit

Permalink
Fixes timezone bias on Windows
Browse files Browse the repository at this point in the history
`GetTimeZoneInformation`returns the bias in minutes already, so no need to adjust it.

Also handle the return code since it determines if the time zone is in the daylight saving range.

Ref: https://learn.microsoft.com/en-us/windows/win32/api/timezoneapi/nf-timezoneapi-gettimezoneinformation
Fixes: saghul/txiki.js#325
  • Loading branch information
saghul committed Dec 9, 2024
1 parent 66732e7 commit 53b641d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -43386,9 +43386,14 @@ static const JSCFunctionListEntry js_math_obj[] = {
between UTC time and local time 'd' in minutes */
static int getTimezoneOffset(int64_t time) {
#if defined(_WIN32)
TIME_ZONE_INFORMATION time_zone_info;
GetTimeZoneInformation(&time_zone_info);
return (int)time_zone_info.Bias / 60;
DWORD r;
TIME_ZONE_INFORMATION t;
r = GetTimeZoneInformation(&t);
if (r == TIME_ZONE_ID_INVALID)
return 0;
if (r == TIME_ZONE_ID_DAYLIGHT)
return (int)(t.Bias + t.DaylightBias);
return (int)t.Bias;
#else
time_t ti;
struct tm tm;
Expand Down

0 comments on commit 53b641d

Please sign in to comment.