wsd: getSteadyClockAsString now includes millis
Change-Id: I1c1e15c5271cd2d9346eaf3a29d11693020e419b Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
This commit is contained in:
parent
05dc8a0f84
commit
381d84ea8d
2 changed files with 18 additions and 4 deletions
|
@ -925,13 +925,26 @@ namespace Util
|
||||||
return timestamp;
|
return timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the given time_point as string in the local time.
|
||||||
|
/// Format: Thu Jan 27 03:45:27.123 2022
|
||||||
std::string getSteadyClockAsString(const std::chrono::steady_clock::time_point &time)
|
std::string getSteadyClockAsString(const std::chrono::steady_clock::time_point &time)
|
||||||
{
|
{
|
||||||
auto now = std::chrono::steady_clock::now();
|
auto now = std::chrono::steady_clock::now();
|
||||||
const std::time_t t = std::chrono::system_clock::to_time_t(
|
const auto corrected = std::chrono::system_clock::now() + (time - now);
|
||||||
std::chrono::time_point_cast<std::chrono::seconds>(
|
const auto ms = std::chrono::time_point_cast<std::chrono::milliseconds>(corrected);
|
||||||
std::chrono::system_clock::now() + (time - now)));
|
const std::time_t t = std::chrono::system_clock::to_time_t(ms);
|
||||||
return std::ctime(&t);
|
const int msFraction =
|
||||||
|
std::chrono::duration_cast<std::chrono::milliseconds>(corrected.time_since_epoch())
|
||||||
|
.count() %
|
||||||
|
1000;
|
||||||
|
|
||||||
|
std::tm tm;
|
||||||
|
localtime_r(&t, &tm);
|
||||||
|
|
||||||
|
char buffer[128] = { 0 };
|
||||||
|
const size_t offset = std::strftime(buffer, 80, "%a %b %d %H:%M", &tm);
|
||||||
|
sprintf(&buffer[offset], ".%3d %d", msFraction, tm.tm_year + 1900);
|
||||||
|
return std::string(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isFuzzing()
|
bool isFuzzing()
|
||||||
|
|
|
@ -1219,6 +1219,7 @@ int main(int argc, char**argv)
|
||||||
std::chrono::system_clock::time_point iso8601ToTimestamp(const std::string& iso8601Time, const std::string& logName);
|
std::chrono::system_clock::time_point iso8601ToTimestamp(const std::string& iso8601Time, const std::string& logName);
|
||||||
|
|
||||||
/// conversion from steady_clock for debugging / tracing
|
/// conversion from steady_clock for debugging / tracing
|
||||||
|
/// Format (local time): Thu Jan 27 03:45:27.123 2022
|
||||||
std::string getSteadyClockAsString(const std::chrono::steady_clock::time_point &time);
|
std::string getSteadyClockAsString(const std::chrono::steady_clock::time_point &time);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue