Skip to content

Commit

Permalink
Do not return pointer to local from get_timezone
Browse files Browse the repository at this point in the history
The pointed at variable was also a wchar_t array, not char. Since Win32
does not provide abbreviated timezone names, express the timezone as a
an RFC3339-style numeric offset.
  • Loading branch information
skeeto committed Jan 17, 2025
1 parent 1ed0333 commit e366967
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,14 +507,14 @@ const char *get_timezone(const struct tm *local_time)
#ifdef _WIN32
// Windows-specific code
TIME_ZONE_INFORMATION tz_info;
if (GetTimeZoneInformation(&tz_info) == TIME_ZONE_ID_DAYLIGHT && local_time->tm_isdst > 0)
{
return tz_info.DaylightName; // DST time zone name
}
else
{
return tz_info.StandardName; // Standard time zone name
}
GetTimeZoneInformation(&tz_info);

static char tzbuf[8];
char sign = tz_info.Bias > 0 ? '-' : '+';
long hours = labs(tz_info.Bias) / 60;
long minutes = labs(tz_info.Bias) % 60;
snprintf(tzbuf, sizeof(tzbuf), "%c%02ld:%02ld", sign, hours, minutes);
return tzbuf;
#else
// Unix-like systems (Linux/macOS) code
extern char *tzname[2]; // tzname[0] is standard, tzname[1] is DST
Expand Down

0 comments on commit e366967

Please sign in to comment.