From 1391e1339e7205b84b6e68510cd5bc287d9c3203 Mon Sep 17 00:00:00 2001 From: Ty Date: Wed, 30 Jul 2025 16:28:20 -0400 Subject: [PATCH] ImGui: Use localtime_r/s instead of fmt::localtime fmt::localtime is deprecated --- pcsx2/ImGui/FullscreenUI.cpp | 13 ++++++++++++- pcsx2/ImGui/ImGuiOverlays.cpp | 18 ++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/pcsx2/ImGui/FullscreenUI.cpp b/pcsx2/ImGui/FullscreenUI.cpp index e831ee56d4..643c4a0c53 100644 --- a/pcsx2/ImGui/FullscreenUI.cpp +++ b/pcsx2/ImGui/FullscreenUI.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -1440,7 +1441,17 @@ void FullscreenUI::DrawLandingTemplate(ImVec2* menu_pos, ImVec2* menu_size) // draw time ImVec2 time_pos; { - heading_str.format(FSUI_FSTR("{:%H:%M}"), fmt::localtime(std::time(nullptr))); + // Waiting on (apple)clang support for P0355R7 + // Migrate to std::chrono::current_zone and zoned_time then + const auto utc_now = std::chrono::system_clock::now(); + const auto utc_time_t = std::chrono::system_clock::to_time_t(utc_now); + std::tm tm_local = {}; +#ifdef _MSC_VER + localtime_s(&tm_local, &utc_time_t); +#else + localtime_r(&utc_time_t, &tm_local); +#endif + heading_str.format(FSUI_FSTR("{:%H:%M}"), tm_local); const ImVec2 time_size = heading_font.first->CalcTextSizeA(heading_font.second, FLT_MAX, 0.0f, "00:00"); time_pos = ImVec2(heading_size.x - LayoutScale(LAYOUT_MENU_BUTTON_X_PADDING) - time_size.x, diff --git a/pcsx2/ImGui/ImGuiOverlays.cpp b/pcsx2/ImGui/ImGuiOverlays.cpp index 1dad022dbf..4f4e95ad99 100644 --- a/pcsx2/ImGui/ImGuiOverlays.cpp +++ b/pcsx2/ImGui/ImGuiOverlays.cpp @@ -1069,7 +1069,14 @@ void SaveStateSelectorUI::InitializeListEntry(const std::string& serial, u32 crc } li->title = fmt::format(TRANSLATE_FS("ImGuiOverlays", "Save Slot {0}"), slot); - li->summary = fmt::format(TRANSLATE_FS("ImGuiOverlays", DATE_TIME_FORMAT), fmt::localtime(sd.ModificationTime)); + + std::tm tm_local = {}; +#ifdef _MSC_VER + localtime_s(&tm_local, &sd.ModificationTime); +#else + localtime_r(&sd.ModificationTime, &tm_local); +#endif + li->summary = fmt::format(TRANSLATE_FS("ImGuiOverlays", DATE_TIME_FORMAT), tm_local); li->filename = Path::GetFileName(path); u32 screenshot_width, screenshot_height; @@ -1268,8 +1275,15 @@ void SaveStateSelectorUI::ShowSlotOSDMessage() const std::string filename = VMManager::GetSaveStateFileName(serial.c_str(), crc, slot); FILESYSTEM_STAT_DATA sd; std::string date; + + std::tm tm_local = {}; +#ifdef _MSC_VER + localtime_s(&tm_local, &sd.ModificationTime); +#else + localtime_r(&sd.ModificationTime, &tm_local); +#endif if (!filename.empty() && FileSystem::StatFile(filename.c_str(), &sd)) - date = fmt::format(TRANSLATE_FS("ImGuiOverlays", DATE_TIME_FORMAT), fmt::localtime(sd.ModificationTime)); + date = fmt::format(TRANSLATE_FS("ImGuiOverlays", DATE_TIME_FORMAT), tm_local); else date = TRANSLATE_STR("ImGuiOverlays", "no save yet");