Use and propagate microsecond-precision timestamps to FormatTime

This enables sub-second precision timestamp formatting for logs and
clients without server-time.
This commit is contained in:
Vladimir Panteleev
2017-10-24 21:45:44 +00:00
parent 901a21e91b
commit 03c4c0b165
6 changed files with 21 additions and 10 deletions
+11 -3
View File
@@ -603,17 +603,25 @@ CString& CUser::ExpandString(const CString& sStr, CString& sRet) const {
}
CString CUser::AddTimestamp(const CString& sStr) const {
time_t tm;
return AddTimestamp(time(&tm), sStr);
timeval tv;
gettimeofday(&tv, nullptr);
return AddTimestamp(tv, sStr);
}
CString CUser::AddTimestamp(time_t tm, const CString& sStr) const {
timeval tv;
tv.tv_sec = tm;
tv.tv_usec = 0;
return AddTimestamp(tv, sStr);
}
CString CUser::AddTimestamp(timeval tv, const CString& sStr) const {
CString sRet = sStr;
if (!GetTimestampFormat().empty() &&
(m_bAppendTimestamp || m_bPrependTimestamp)) {
CString sTimestamp =
CUtils::FormatTime(tm, GetTimestampFormat(), m_sTimezone);
CUtils::FormatTime(tv, GetTimestampFormat(), m_sTimezone);
if (sTimestamp.empty()) {
return sRet;
}