Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/utils/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@

#include "utils/logging.h"

#include <version>
#if __cpp_lib_format >= 201907L
#include <chrono>
#include <format>
#endif
#include <iomanip>
#include <iostream>
#include <thread>
Expand Down Expand Up @@ -100,8 +105,26 @@ std::chrono::time_point<std::chrono::system_clock> SteadyClockToSystemClock(
time - std::chrono::steady_clock::now());
}

namespace {
#if __cpp_lib_format >= 201907L
const std::chrono::time_zone* GetCurrentTimeZone() {
try {
return std::chrono::current_zone();
} catch (const std::runtime_error&) {
// If the current time zone cannot be determined, fall back to UTC.
return nullptr;
}
}
#endif
} // namespace

std::string FormatTime(
std::chrono::time_point<std::chrono::system_clock> time) {
#if __cpp_lib_format >= 201907L
static auto* zone = GetCurrentTimeZone();
return zone ? std::format("{0:%m%d %T}", zone->to_local(time))
: std::format("{0:%m%d %T}", time);
#else
Comment thread
Menkib64 marked this conversation as resolved.
static Mutex mutex;

std::ostringstream ss;
Expand All @@ -121,6 +144,7 @@ std::string FormatTime(
<< std::setfill('0') << std::setw(6) << us;
}
return ss.str();
#endif
}

} // namespace lczero
} // namespace lczero