ImGui: Use localtime_r/s instead of fmt::localtime

fmt::localtime is deprecated
This commit is contained in:
Ty 2025-07-30 16:28:20 -04:00 committed by Ty
parent 2f2614737a
commit 1391e1339e
2 changed files with 28 additions and 3 deletions

View File

@ -50,6 +50,7 @@
#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <thread>
#include <utility>
#include <vector>
@ -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,

View File

@ -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");