From 52410813f22def236c7ce28390fbd18cb0b582d4 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sun, 18 Feb 2024 04:40:25 +0100 Subject: Common: Add utility function that wraps localtime_s() or localtime_t(). --- Source/Core/Common/TimeUtil.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Source/Core/Common/TimeUtil.cpp (limited to 'Source/Core/Common/TimeUtil.cpp') diff --git a/Source/Core/Common/TimeUtil.cpp b/Source/Core/Common/TimeUtil.cpp new file mode 100644 index 0000000000..39d989fb3f --- /dev/null +++ b/Source/Core/Common/TimeUtil.cpp @@ -0,0 +1,24 @@ +// Copyright 2024 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "Common/TimeUtil.h" + +#include +#include + +namespace Common +{ +std::optional 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; +#endif + return local_time; +} +} // Namespace Common -- cgit v1.2.3