PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
time.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
27#pragma once
28
29#include <ctime>
30
31namespace kcenon::pacs::compat {
32
43inline std::tm* localtime_safe(const std::time_t* time, std::tm* result) {
44#if defined(_WIN32) || defined(_WIN64)
45 // Windows: localtime_s returns errno_t (0 on success)
46 // Parameter order: (tm*, time_t*)
47 return localtime_s(result, time) == 0 ? result : nullptr;
48#else
49 // POSIX: localtime_r returns tm* (result on success, nullptr on failure)
50 // Parameter order: (time_t*, tm*)
51 return localtime_r(time, result);
52#endif
53}
54
65inline std::tm* gmtime_safe(const std::time_t* time, std::tm* result) {
66#if defined(_WIN32) || defined(_WIN64)
67 // Windows: gmtime_s returns errno_t (0 on success)
68 return gmtime_s(result, time) == 0 ? result : nullptr;
69#else
70 // POSIX: gmtime_r returns tm*
71 return gmtime_r(time, result);
72#endif
73}
74
75} // namespace kcenon::pacs::compat
std::tm * localtime_safe(const std::time_t *time, std::tm *result)
Cross-platform thread-safe local time conversion.
Definition time.h:43
std::tm * gmtime_safe(const std::time_t *time, std::tm *result)
Cross-platform thread-safe UTC time conversion.
Definition time.h:65