From 40b60f3c86bc0943ee0090650b23ec17e7234247 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 20 Mar 2022 18:59:27 +0100 Subject: [PATCH] Backported: - Fix DST Error on Windows (cherry picked from commit 4802f15) - ztc0611 (https://github.com/godotengine/godot/commit/658877c350dc3062d633902aac06050e1c3352e0) --- platform/windows/os_windows.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index c8d29ff36..e7f0e87b4 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -2377,12 +2377,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 { @@ -2405,16 +2412,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; }