From 0aecfc92540618508568b5c7e8a050d36cf5322b Mon Sep 17 00:00:00 2001 From: James Date: Thu, 8 Sep 2022 13:36:10 +0800 Subject: Fixes #65377: get_datetime_* functions can return wrong values --- platform/uwp/os_uwp.cpp | 37 ++++++++++++++++--------------------- platform/uwp/os_uwp.h | 3 +-- 2 files changed, 17 insertions(+), 23 deletions(-) (limited to 'platform/uwp') diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp index 494f5ec4b9..791328964b 100644 --- a/platform/uwp/os_uwp.cpp +++ b/platform/uwp/os_uwp.cpp @@ -444,7 +444,7 @@ String OS_UWP::get_name() const { return "UWP"; } -OS::Date OS_UWP::get_date(bool p_utc) const { +OS::DateTime OS_UWP::get_datetime(bool p_utc) const { SYSTEMTIME systemtime; if (p_utc) { GetSystemTime(&systemtime); @@ -452,28 +452,23 @@ OS::Date OS_UWP::get_date(bool p_utc) const { GetLocalTime(&systemtime); } - Date date; - date.day = systemtime.wDay; - date.month = Month(systemtime.wMonth); - date.weekday = Weekday(systemtime.wDayOfWeek); - date.year = systemtime.wYear; - date.dst = false; - return date; -} - -OS::Time OS_UWP::get_time(bool p_utc) const { - SYSTEMTIME systemtime; - if (p_utc) { - GetSystemTime(&systemtime); - } else { - GetLocalTime(&systemtime); + //Get DST information from Windows, but only if p_utc is false. + TIME_ZONE_INFORMATION info; + bool daylight = false; + if (!p_utc && GetTimeZoneInformation(&info) == TIME_ZONE_ID_DAYLIGHT) { + daylight = true; } - Time time; - time.hour = systemtime.wHour; - time.min = systemtime.wMinute; - time.sec = systemtime.wSecond; - return time; + DateTime dt; + dt.year = systemtime.wYear; + dt.month = Month(systemtime.wMonth); + dt.day = systemtime.wDay; + dt.weekday = Weekday(systemtime.wDayOfWeek); + dt.hour = systemtime.wHour; + dt.minute = systemtime.wMinute; + dt.second = systemtime.wSecond; + dt.dst = daylight; + return dt; } OS::TimeZoneInfo OS_UWP::get_time_zone_info() const { diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h index 5a58486ee7..7d4224cf74 100644 --- a/platform/uwp/os_uwp.h +++ b/platform/uwp/os_uwp.h @@ -184,8 +184,7 @@ public: virtual String get_name() const; - virtual Date get_date(bool p_utc) const; - virtual Time get_time(bool p_utc) const; + virtual DateTime get_datetime(bool p_utc) const; virtual TimeZoneInfo get_time_zone_info() const; virtual uint64_t get_unix_time() const; -- cgit v1.2.3