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
24#pragma once
25
26#include <ctime>
27
28namespace kcenon::pacs::compat {
29
40inline std::tm* localtime_safe(const std::time_t* time, std::tm* result) {
41#if defined(_WIN32) || defined(_WIN64)
42 // Windows: localtime_s returns errno_t (0 on success)
43 // Parameter order: (tm*, time_t*)
44 return localtime_s(result, time) == 0 ? result : nullptr;
45#else
46 // POSIX: localtime_r returns tm* (result on success, nullptr on failure)
47 // Parameter order: (time_t*, tm*)
48 return localtime_r(time, result);
49#endif
50}
51
62inline std::tm* gmtime_safe(const std::time_t* time, std::tm* result) {
63#if defined(_WIN32) || defined(_WIN64)
64 // Windows: gmtime_s returns errno_t (0 on success)
65 return gmtime_s(result, time) == 0 ? result : nullptr;
66#else
67 // POSIX: gmtime_r returns tm*
68 return gmtime_r(time, result);
69#endif
70}
71
72} // 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:40
std::tm * gmtime_safe(const std::time_t *time, std::tm *result)
Cross-platform thread-safe UTC time conversion.
Definition time.h:62