summaryrefslogtreecommitdiff
path: root/Source/Core/Common
diff options
context:
space:
mode:
authorTilka <tilkax@gmail.com>2025-06-08 04:04:37 +0100
committerGitHub <noreply@github.com>2025-06-08 04:04:37 +0100
commit19fbbf0dba32ad98fe791804cfd464ced91464f5 (patch)
tree24fd224e2185a3c77c57fb50f8af63ce0df21493 /Source/Core/Common
parent1786e34bd34db61b910064741294e87bfb4d3e91 (diff)
parent4b65cc9a4c51af4308f748b3e7bf25d80db83860 (diff)
Merge pull request #13727 from JoshuaVandaele/fmt-11.2.0-localtime-deprec
fmt: Replace deprecated `fmt::localtime` usage with `Common::LocalTime`
Diffstat (limited to 'Source/Core/Common')
-rw-r--r--Source/Core/Common/FatFsUtil.cpp8
-rw-r--r--Source/Core/Common/SettingsHandler.cpp3
-rw-r--r--Source/Core/Common/TimeUtil.cpp12
-rw-r--r--Source/Core/Common/TimeUtil.h2
4 files changed, 11 insertions, 14 deletions
diff --git a/Source/Core/Common/FatFsUtil.cpp b/Source/Core/Common/FatFsUtil.cpp
index 9c513d5e42..80e2c424b4 100644
--- a/Source/Core/Common/FatFsUtil.cpp
+++ b/Source/Core/Common/FatFsUtil.cpp
@@ -25,6 +25,7 @@
#include "Common/Logging/Log.h"
#include "Common/ScopeGuard.h"
#include "Common/StringUtil.h"
+#include "Common/TimeUtil.h"
#include "Core/Config/MainSettings.h"
@@ -95,12 +96,7 @@ int SDCardDiskIOCtl(File::IOFile* image, u8 pdrv, u8 cmd, void* buff)
u32 GetSystemTimeFAT()
{
const std::time_t time = std::time(nullptr);
- std::tm tm;
-#ifdef _WIN32
- localtime_s(&tm, &time);
-#else
- localtime_r(&time, &tm);
-#endif
+ std::tm tm = *Common::LocalTime(time);
DWORD fattime = 0;
fattime |= (tm.tm_year - 80) << 25;
diff --git a/Source/Core/Common/SettingsHandler.cpp b/Source/Core/Common/SettingsHandler.cpp
index 6cc9f5a8fe..b0faf6f6f0 100644
--- a/Source/Core/Common/SettingsHandler.cpp
+++ b/Source/Core/Common/SettingsHandler.cpp
@@ -122,7 +122,6 @@ std::string SettingsWriter::GenerateSerialNumber()
// Must be 9 characters at most; otherwise the serial number will be rejected by SDK libraries,
// as there is a check to ensure the string length is strictly lower than 10.
- // 3 for %j, 2 for %H, 2 for %M, 2 for %S.
- return fmt::format("{:%j%H%M%S}", fmt::localtime(t));
+ return fmt::format("{:09}", t % 1000000000);
}
} // namespace Common
diff --git a/Source/Core/Common/TimeUtil.cpp b/Source/Core/Common/TimeUtil.cpp
index 39d989fb3f..93327e9136 100644
--- a/Source/Core/Common/TimeUtil.cpp
+++ b/Source/Core/Common/TimeUtil.cpp
@@ -2,23 +2,25 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "Common/TimeUtil.h"
+#include "Common/Logging/Log.h"
#include <ctime>
#include <optional>
namespace Common
{
-std::optional<std::tm> Localtime(std::time_t time)
+std::optional<std::tm> LocalTime(std::time_t time)
{
std::tm local_time;
#ifdef _MSC_VER
if (localtime_s(&local_time, &time) != 0)
- return std::nullopt;
#else
- std::tm* result = localtime_r(&time, &local_time);
- if (result != &local_time)
- return std::nullopt;
+ if (localtime_r(&time, &local_time) == NULL)
#endif
+ {
+ ERROR_LOG_FMT(COMMON, "Failed to convert time to local time: {}", std::strerror(errno));
+ return std::nullopt;
+ }
return local_time;
}
} // Namespace Common
diff --git a/Source/Core/Common/TimeUtil.h b/Source/Core/Common/TimeUtil.h
index ff9ca02a12..3abb525e5e 100644
--- a/Source/Core/Common/TimeUtil.h
+++ b/Source/Core/Common/TimeUtil.h
@@ -9,5 +9,5 @@
namespace Common
{
// Threadsafe and error-checking variant of std::localtime()
-std::optional<std::tm> Localtime(std::time_t time);
+std::optional<std::tm> LocalTime(std::time_t time);
} // Namespace Common