Fix DST Error on Windows

(cherry picked from commit 4802f15231)
This commit is contained in:
ztco224 2022-03-17 06:28:08 -04:00 committed by Rémi Verschelde
parent 451d3d378c
commit b86b4e5004
1 changed files with 13 additions and 3 deletions

View File

@ -2416,12 +2416,19 @@ OS::Date OS_Windows::get_date(bool utc) const {
else
GetLocalTime(&systemtime);
// Get DST information from Windows, but only if utc is false.
TIME_ZONE_INFORMATION info;
bool daylight = false;
if (!utc && GetTimeZoneInformation(&info) == TIME_ZONE_ID_DAYLIGHT) {
daylight = true;
}
Date date;
date.day = systemtime.wDay;
date.month = Month(systemtime.wMonth);
date.weekday = Weekday(systemtime.wDayOfWeek);
date.year = systemtime.wYear;
date.dst = false;
date.dst = daylight;
return date;
}
OS::Time OS_Windows::get_time(bool utc) const {
@ -2444,16 +2451,19 @@ OS::TimeZoneInfo OS_Windows::get_time_zone_info() const {
if (GetTimeZoneInformation(&info) == TIME_ZONE_ID_DAYLIGHT)
daylight = true;
// Daylight Bias needs to be added to the bias if DST is in effect, or else it will not properly update.
TimeZoneInfo ret;
if (daylight) {
ret.name = info.DaylightName;
ret.bias = info.Bias + info.DaylightBias;
} else {
ret.name = info.StandardName;
ret.bias = info.Bias + info.StandardBias;
}
// Bias value returned by GetTimeZoneInformation is inverted of what we expect
// For example on GMT-3 GetTimeZoneInformation return a Bias of 180, so invert the value to get -180
ret.bias = -info.Bias;
// For example, on GMT-3 GetTimeZoneInformation return a Bias of 180, so invert the value to get -180
ret.bias = -ret.bias;
return ret;
}