Skip to content

Commit

Permalink
time/Zone: add native Windows implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Jun 1, 2022
1 parent db03db0 commit 8333927
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/time/Zone.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,35 @@

#include "Zone.hxx"

#ifdef _WIN32
#include <profileapi.h>
#include <sysinfoapi.h>
#include <timezoneapi.h>
#else
#include <time.h>
#endif

int
GetTimeZoneOffset() noexcept
{
time_t t = 1234567890;
#ifdef _WIN32
struct tm *p = gmtime(&t);
TIME_ZONE_INFORMATION TimeZoneInformation;
DWORD tzi = GetTimeZoneInformation(&TimeZoneInformation);

int offset = -TimeZoneInformation.Bias * 60;
if (tzi == TIME_ZONE_ID_STANDARD)
offset -= TimeZoneInformation.StandardBias * 60;

if (tzi == TIME_ZONE_ID_DAYLIGHT)
offset -= TimeZoneInformation.DaylightBias * 60;

return offset;
#else
time_t t = 1234567890;
struct tm tm;
tm.tm_isdst = 0;
struct tm *p = &tm;
gmtime_r(&t, p);
#endif
return t - mktime(p);
#endif
}

0 comments on commit 8333927

Please sign in to comment.