| 1 | // Copyright 2024 Dolphin Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #include "Common/TimeUtil.h" |
| 5 | |
| 6 | #include <cstring> |
| 7 | #include <ctime> |
| 8 | #include <optional> |
| 9 | |
| 10 | #include "Common/Logging/Log.h" |
| 11 | |
| 12 | namespace Common |
| 13 | { |
| 14 | std::optional<std::tm> LocalTime(std::time_t time) |
| 15 | { |
| 16 | std::tm local_time; |
| 17 | #ifdef _MSC_VER |
| 18 | if (localtime_s(&local_time, &time) != 0) |
| 19 | #else |
| 20 | if (localtime_r(&time, &local_time) == NULL) |
| 21 | #endif |
| 22 | { |
| 23 | ERROR_LOG_FMT(COMMON, "Failed to convert time to local time: {}", std::strerror(errno)); |
| 24 | return std::nullopt; |
| 25 | } |
| 26 | return local_time; |
| 27 | } |
| 28 | } // Namespace Common |