diff options
author | James <gotnospirit@gmail.com> | 2022-09-08 13:36:10 +0800 |
---|---|---|
committer | James <gotnospirit@gmail.com> | 2022-09-10 07:58:38 +0800 |
commit | 0aecfc92540618508568b5c7e8a050d36cf5322b (patch) | |
tree | ad7fe94efad6acb9deb5c160ba672cf37f9f8b0f /platform | |
parent | 27e132347324318567419ac5039d51338d7d4f0e (diff) |
Fixes #65377: get_datetime_* functions can return wrong values
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/export/export_plugin.cpp | 15 | ||||
-rw-r--r-- | platform/linuxbsd/os_linuxbsd.cpp | 7 | ||||
-rw-r--r-- | platform/macos/export/export_plugin.cpp | 30 | ||||
-rw-r--r-- | platform/uwp/os_uwp.cpp | 37 | ||||
-rw-r--r-- | platform/uwp/os_uwp.h | 3 | ||||
-rw-r--r-- | platform/windows/os_windows.cpp | 34 | ||||
-rw-r--r-- | platform/windows/os_windows.h | 3 |
7 files changed, 53 insertions, 76 deletions
diff --git a/platform/android/export/export_plugin.cpp b/platform/android/export/export_plugin.cpp index 0f8ef3f7d6..e5656bd00b 100644 --- a/platform/android/export/export_plugin.cpp +++ b/platform/android/export/export_plugin.cpp @@ -569,16 +569,15 @@ bool EditorExportPlatformAndroid::_should_compress_asset(const String &p_path, c } zip_fileinfo EditorExportPlatformAndroid::get_zip_fileinfo() { - OS::Time time = OS::get_singleton()->get_time(); - OS::Date date = OS::get_singleton()->get_date(); + OS::DateTime dt = OS::get_singleton()->get_datetime(); zip_fileinfo zipfi; - zipfi.tmz_date.tm_hour = time.hour; - zipfi.tmz_date.tm_mday = date.day; - zipfi.tmz_date.tm_min = time.minute; - zipfi.tmz_date.tm_mon = date.month - 1; // tm_mon is zero indexed - zipfi.tmz_date.tm_sec = time.second; - zipfi.tmz_date.tm_year = date.year; + zipfi.tmz_date.tm_year = dt.year; + zipfi.tmz_date.tm_mon = dt.month - 1; // tm_mon is zero indexed + zipfi.tmz_date.tm_mday = dt.day; + zipfi.tmz_date.tm_hour = dt.hour; + zipfi.tmz_date.tm_min = dt.minute; + zipfi.tmz_date.tm_sec = dt.second; zipfi.dosDate = 0; zipfi.external_fa = 0; zipfi.internal_fa = 0; diff --git a/platform/linuxbsd/os_linuxbsd.cpp b/platform/linuxbsd/os_linuxbsd.cpp index 61faf3061c..f0d7b6ede5 100644 --- a/platform/linuxbsd/os_linuxbsd.cpp +++ b/platform/linuxbsd/os_linuxbsd.cpp @@ -686,10 +686,9 @@ Error OS_LinuxBSD::move_to_trash(const String &p_path) { String renamed_path = path.get_base_dir() + "/" + file_name; // Generates the .trashinfo file - OS::Date date = OS::get_singleton()->get_date(false); - OS::Time time = OS::get_singleton()->get_time(false); - String timestamp = vformat("%04d-%02d-%02dT%02d:%02d:", date.year, (int)date.month, date.day, time.hour, time.minute); - timestamp = vformat("%s%02d", timestamp, time.second); // vformat only supports up to 6 arguments. + OS::DateTime dt = OS::get_singleton()->get_datetime(false); + String timestamp = vformat("%04d-%02d-%02dT%02d:%02d:", dt.year, (int)dt.month, dt.day, dt.hour, dt.minute); + timestamp = vformat("%s%02d", timestamp, dt.second); // vformat only supports up to 6 arguments. String trash_info = "[Trash Info]\nPath=" + path.uri_encode() + "\nDeletionDate=" + timestamp + "\n"; { Error err; diff --git a/platform/macos/export/export_plugin.cpp b/platform/macos/export/export_plugin.cpp index 50104aced5..070830c486 100644 --- a/platform/macos/export/export_plugin.cpp +++ b/platform/macos/export/export_plugin.cpp @@ -1641,16 +1641,15 @@ void EditorExportPlatformMacOS::_zip_folder_recursive(zipFile &p_zip, const Stri continue; } if (da->is_link(f)) { - OS::Time time = OS::get_singleton()->get_time(); - OS::Date date = OS::get_singleton()->get_date(); + OS::DateTime dt = OS::get_singleton()->get_datetime(); zip_fileinfo zipfi; - zipfi.tmz_date.tm_hour = time.hour; - zipfi.tmz_date.tm_mday = date.day; - zipfi.tmz_date.tm_min = time.minute; - zipfi.tmz_date.tm_mon = date.month - 1; // Note: "tm" month range - 0..11, Godot month range - 1..12, https://www.cplusplus.com/reference/ctime/tm/ - zipfi.tmz_date.tm_sec = time.second; - zipfi.tmz_date.tm_year = date.year; + zipfi.tmz_date.tm_year = dt.year; + zipfi.tmz_date.tm_mon = dt.month - 1; // Note: "tm" month range - 0..11, Godot month range - 1..12, https://www.cplusplus.com/reference/ctime/tm/ + zipfi.tmz_date.tm_mday = dt.day; + zipfi.tmz_date.tm_hour = dt.hour; + zipfi.tmz_date.tm_min = dt.minute; + zipfi.tmz_date.tm_sec = dt.second; zipfi.dosDate = 0; // 0120000: symbolic link type // 0000755: permissions rwxr-xr-x @@ -1686,16 +1685,15 @@ void EditorExportPlatformMacOS::_zip_folder_recursive(zipFile &p_zip, const Stri } else { bool is_executable = (p_folder.ends_with("MacOS") && (f == p_pkg_name)) || p_folder.ends_with("Helpers") || f.ends_with(".command"); - OS::Time time = OS::get_singleton()->get_time(); - OS::Date date = OS::get_singleton()->get_date(); + OS::DateTime dt = OS::get_singleton()->get_datetime(); zip_fileinfo zipfi; - zipfi.tmz_date.tm_hour = time.hour; - zipfi.tmz_date.tm_mday = date.day; - zipfi.tmz_date.tm_min = time.minute; - zipfi.tmz_date.tm_mon = date.month - 1; // Note: "tm" month range - 0..11, Godot month range - 1..12, https://www.cplusplus.com/reference/ctime/tm/ - zipfi.tmz_date.tm_sec = time.second; - zipfi.tmz_date.tm_year = date.year; + zipfi.tmz_date.tm_year = dt.year; + zipfi.tmz_date.tm_mon = dt.month - 1; // Note: "tm" month range - 0..11, Godot month range - 1..12, https://www.cplusplus.com/reference/ctime/tm/ + zipfi.tmz_date.tm_mday = dt.day; + zipfi.tmz_date.tm_hour = dt.hour; + zipfi.tmz_date.tm_min = dt.minute; + zipfi.tmz_date.tm_sec = dt.second; zipfi.dosDate = 0; // 0100000: regular file type // 0000755: permissions rwxr-xr-x 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; diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index b7794bbbf8..2c268ff3d5 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -290,7 +290,7 @@ String OS_Windows::get_name() const { return "Windows"; } -OS::Date OS_Windows::get_date(bool p_utc) const { +OS::DateTime OS_Windows::get_datetime(bool p_utc) const { SYSTEMTIME systemtime; if (p_utc) { GetSystemTime(&systemtime); @@ -305,28 +305,16 @@ OS::Date OS_Windows::get_date(bool p_utc) const { daylight = true; } - Date date; - date.day = systemtime.wDay; - date.month = Month(systemtime.wMonth); - date.weekday = Weekday(systemtime.wDayOfWeek); - date.year = systemtime.wYear; - date.dst = daylight; - return date; -} - -OS::Time OS_Windows::get_time(bool p_utc) const { - SYSTEMTIME systemtime; - if (p_utc) { - GetSystemTime(&systemtime); - } else { - GetLocalTime(&systemtime); - } - - Time time; - time.hour = systemtime.wHour; - time.minute = systemtime.wMinute; - time.second = 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_Windows::get_time_zone_info() const { diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index 3e054c068c..53451b780e 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -146,8 +146,7 @@ public: virtual void initialize_joypads() override {} - virtual Date get_date(bool p_utc) const override; - virtual Time get_time(bool p_utc) const override; + virtual DateTime get_datetime(bool p_utc) const override; virtual TimeZoneInfo get_time_zone_info() const override; virtual double get_unix_time() const override; |