Skip to content

Commit

Permalink
Fix time zone display on Windows
Browse files Browse the repository at this point in the history
* Update `get_timezone` to return time zone bias when on Windows
  • Loading branch information
da-luce authored Jan 17, 2025
2 parents 2093e10 + e366967 commit aa9587b
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 @@ -506,14 +506,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 aa9587b

Please sign in to comment.