diff --git a/Source/Core/Core/IOS/Network/KD/NetKDTime.cpp b/Source/Core/Core/IOS/Network/KD/NetKDTime.cpp index 6764be4053..6095ae458d 100644 --- a/Source/Core/Core/IOS/Network/KD/NetKDTime.cpp +++ b/Source/Core/Core/IOS/Network/KD/NetKDTime.cpp @@ -5,6 +5,8 @@ #include +#include + #include "Common/CommonTypes.h" #include "Core/HW/EXI/EXI_DeviceIPL.h" #include "Core/HW/Memmap.h" @@ -93,10 +95,10 @@ u64 NetKDTimeDevice::GetAdjustedUTC() const time_t dst_diff{}; const time_t current_time = CEXIIPL::GetEmulatedTime(GetSystem(), CEXIIPL::UNIX_EPOCH); - tm* const gm_time = gmtime(¤t_time); + tm gm_time = fmt::gmtime(current_time); - const u32 emulated_time = mktime(gm_time); - if (gm_time->tm_isdst == 1) + const u32 emulated_time = mktime(&gm_time); + if (gm_time.tm_isdst == 1) dst_diff = 3600; return u64(s64(emulated_time) + utcdiff - dst_diff); @@ -108,10 +110,10 @@ void NetKDTimeDevice::SetAdjustedUTC(u64 wii_utc) time_t dst_diff{}; const time_t current_time = CEXIIPL::GetEmulatedTime(GetSystem(), CEXIIPL::UNIX_EPOCH); - tm* const gm_time = gmtime(¤t_time); + tm gm_time = fmt::gmtime(current_time); - const u32 emulated_time = mktime(gm_time); - if (gm_time->tm_isdst == 1) + const u32 emulated_time = mktime(&gm_time); + if (gm_time.tm_isdst == 1) dst_diff = 3600; utcdiff = s64(emulated_time - wii_utc - dst_diff); diff --git a/Source/Core/Core/Movie.cpp b/Source/Core/Core/Movie.cpp index 84b6ddc9f6..1bdf8c56d6 100644 --- a/Source/Core/Core/Movie.cpp +++ b/Source/Core/Core/Movie.cpp @@ -7,8 +7,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -18,6 +18,7 @@ #include #include +#include #include #include "Common/Assert.h" @@ -160,21 +161,19 @@ std::string MovieManager::GetInputDisplay() } // NOTE: GPU Thread -std::string MovieManager::GetRTCDisplay() +std::string MovieManager::GetRTCDisplay() const { using ExpansionInterface::CEXIIPL; - const time_t current_time = - CEXIIPL::GetEmulatedTime(Core::System::GetInstance(), CEXIIPL::UNIX_EPOCH); - const tm* const gm_time = gmtime(¤t_time); + const time_t current_time = CEXIIPL::GetEmulatedTime(m_system, CEXIIPL::UNIX_EPOCH); + const tm gm_time = fmt::gmtime(current_time); - std::ostringstream format_time; - format_time << std::put_time(gm_time, "Date/Time: %c\n"); - return format_time.str(); + // Use current locale for formatting time, as fmt is locale-agnostic by default. + return fmt::format(std::locale{""}, "Date/Time: {:%c}", gm_time); } // NOTE: GPU Thread -std::string MovieManager::GetRerecords() +std::string MovieManager::GetRerecords() const { if (IsMovieActive()) return fmt::format("Rerecords: {}", m_rerecords); diff --git a/Source/Core/Core/Movie.h b/Source/Core/Core/Movie.h index 74b541cc2f..32d160a39c 100644 --- a/Source/Core/Core/Movie.h +++ b/Source/Core/Core/Movie.h @@ -222,8 +222,8 @@ public: WiimoteEmu::ExtensionNumber ext, const WiimoteEmu::EncryptionKey& key); std::string GetInputDisplay(); - std::string GetRTCDisplay(); - std::string GetRerecords(); + std::string GetRTCDisplay() const; + std::string GetRerecords() const; private: void GetSettings(); diff --git a/Source/Core/Core/State.cpp b/Source/Core/Core/State.cpp index 09334242e8..f804b319a5 100644 --- a/Source/Core/Core/State.cpp +++ b/Source/Core/Core/State.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -15,6 +16,7 @@ #include #include +#include #include #include @@ -278,21 +280,11 @@ static double GetSystemTimeAsDouble() static std::string SystemTimeAsDoubleToString(double time) { // revert adjustments from GetSystemTimeAsDouble() to get a normal Unix timestamp again - time_t seconds = static_cast(time) + DOUBLE_TIME_OFFSET; - errno = 0; - tm* local_time = localtime(&seconds); - if (errno != 0 || !local_time) - return ""; + const time_t seconds = static_cast(time) + DOUBLE_TIME_OFFSET; + const tm local_time = fmt::localtime(seconds); -#ifdef _WIN32 - wchar_t tmp[32] = {}; - wcsftime(tmp, std::size(tmp), L"%x %X", local_time); - return WStringToUTF8(tmp); -#else - char tmp[32] = {}; - strftime(tmp, sizeof(tmp), "%x %X", local_time); - return tmp; -#endif + // fmt is locale agnostic by default, so explicitly use current locale. + return fmt::format(std::locale{""}, "{:%x %X}", local_time); } static std::string MakeStateFilename(int number);