From f32104a4967df21e6f7a7a9fb7643de6e844689b Mon Sep 17 00:00:00 2001
From: Florian Schmaus <flow@cs.fau.de>
Date: Sun, 16 Jan 2022 09:37:16 +0100
Subject: [PATCH] [log] Use system_clock instead of high_resolution_clock

According to the 'Notes' section of
https://en.cppreference.com/w/cpp/chrono/high_resolution_clock one
should just use steady_clock or system_clock. Furthermore, the notes
state that with GCC's libstdc++ high_resolution_clock is system_clock,
but for LLVM's libc++ it depends on the configuration (and is
steady_clock). But steady_clock has no to_time_t() member function.

Hence we explicitly uses system_clock now, which always has
to_time_t(), i.e. in libstdc++ and in libc++. This allows us to get
rid of the GLIBCXX (libstdc++) specific code.
---
 emper/log/log.cpp | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/emper/log/log.cpp b/emper/log/log.cpp
index c3599731..b975f1d9 100644
--- a/emper/log/log.cpp
+++ b/emper/log/log.cpp
@@ -24,12 +24,10 @@ using emper::io::GlobalIoContext;
 namespace emper::log {
 
 static void add_timestamp_to(std::ostringstream& logMessage) {
-#if defined __GLIBCXX__
-	static const long NanosInAMinute = 60L * 1000 * 1000 * 1000;
+	using clock = std::chrono::system_clock;
 
-	auto now = std::chrono::high_resolution_clock::now();
-
-	auto now_time_t = std::chrono::high_resolution_clock::to_time_t(now);
+	auto now = clock::now();
+	auto now_time_t = clock::to_time_t(now);
 
 	const std::tm* now_localtime = [&now_time_t] {
 		if constexpr (emper::LOG_TIMESTAMP == emper::LogTimeStamp::utc) {
@@ -52,11 +50,9 @@ static void add_timestamp_to(std::ostringstream& logMessage) {
 	auto time_since_epoch = now_nanos.time_since_epoch();
 	long time_since_epoch_long = time_since_epoch.count();
 
+	const long NanosInAMinute = 60L * 1000 * 1000 * 1000;
 	long remaining_nanos = time_since_epoch_long % NanosInAMinute;
 	logMessage << remaining_nanos;
-#else
-	logMessage << "UNKN_TIME";
-#endif
 }
 
 static std::mutex log_mutex;
-- 
GitLab