diff --git a/retinify/src/logging.cpp b/retinify/src/logging.cpp index ba9aa69..3acc2e9 100644 --- a/retinify/src/logging.cpp +++ b/retinify/src/logging.cpp @@ -92,16 +92,28 @@ struct LogMetadata [[nodiscard]] auto GetCurrentTime() -> std::string { - const std::chrono::system_clock::time_point currentTimePoint = std::chrono::system_clock::now(); - const std::time_t currentTimeT = std::chrono::system_clock::to_time_t(currentTimePoint); - std::tm localTimeStruct{}; - if (localtime_r(¤tTimeT, &localTimeStruct) == nullptr) + const std::time_t now = std::time(nullptr); + + std::tm utc{}; +#if defined(_WIN32) + if (gmtime_s(&utc, &now) != 0) + { + return {}; + } +#else + if (gmtime_r(&now, &utc) == nullptr) { - return std::string{"Invalid time"}; + return {}; } - std::ostringstream timeStream; - timeStream << std::put_time(&localTimeStruct, "%F %T"); - return timeStream.str(); +#endif + + char buffer[32]; + if (std::strftime(buffer, sizeof(buffer), "%Y-%m-%dT%H:%M:%SZ", &utc) == 0) + { + return {}; + } + + return buffer; } inline auto Log(LogLevel level, const char *message, std::source_location location) noexcept -> void