mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Promote server-time formatting to Utils
This commit is contained in:
@@ -428,6 +428,22 @@ CString CUtils::FormatTime(time_t t, const CString& sFormat, const CString& sTim
|
||||
return s;
|
||||
}
|
||||
|
||||
CString CUtils::FormatServerTime(const timeval& tv) {
|
||||
CString s_msec(tv.tv_usec / 1000);
|
||||
while (s_msec.length() < 3) {
|
||||
s_msec = "0" + s_msec;
|
||||
}
|
||||
// TODO support leap seconds properly
|
||||
// TODO support message-tags properly
|
||||
struct tm stm;
|
||||
memset(&stm, 0, sizeof(stm));
|
||||
const time_t secs = tv.tv_sec; // OpenBSD has tv_sec as int, so explicitly convert it to time_t to make gmtime_r() happy
|
||||
gmtime_r(&secs, &stm);
|
||||
char sTime[20] = {};
|
||||
strftime(sTime, sizeof(sTime), "%Y-%m-%dT%H:%M:%S", &stm);
|
||||
return CString(sTime) + "." + s_msec + "Z";
|
||||
}
|
||||
|
||||
namespace {
|
||||
void FillTimezones(const CString& sPath, SCString& result, const CString& sPrefix) {
|
||||
CDir Dir;
|
||||
|
||||
Reference in New Issue
Block a user