inspircd

A modular C++ IRC daemon (ircd). https://www.inspircd.org/
Log | Files | Refs | README

commit da53c17315d3eb0d0177608d306d208bdf05786b
parent 8bbd67b1f7b87df9b36a950b3b699c5b76a1748f
Author: Peter Powell <petpow@saberuk.com>
Date:   Fri,  7 Jun 2019 20:13:23 +0100

Implement support for millisecond level server-time accuracy.

Diffstat:
Minclude/modules/ircv3_servertime.h | 9++++++---
Msrc/modules/m_ircv3_servertime.cpp | 11++++++++---
2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/include/modules/ircv3_servertime.h b/include/modules/ircv3_servertime.h @@ -27,12 +27,15 @@ namespace IRCv3 class API; /** Format a unix timestamp into the format used by server-time. - * @param t Time to format. + * @param secs UNIX timestamp to format. + * @params millisecs Number of milliseconds to format. * @return Time in server-time format, as a string. */ - inline std::string FormatTime(time_t t) + inline std::string FormatTime(time_t secs, long millisecs = 0) { - return InspIRCd::TimeString(t, "%Y-%m-%dT%H:%M:%S.000Z", true); + std::string timestr = InspIRCd::TimeString(secs, "%Y-%m-%dT%H:%M:%S.Z", true); + timestr.insert(20, InspIRCd::Format("%03ld", millisecs)); + return timestr; } } } diff --git a/src/modules/m_ircv3_servertime.cpp b/src/modules/m_ircv3_servertime.cpp @@ -24,16 +24,20 @@ class ServerTimeTag : public IRCv3::ServerTime::Manager, public IRCv3::CapTag<ServerTimeTag> { time_t lasttime; + long lasttimens; std::string lasttimestring; void RefreshTimeString() { const time_t currtime = ServerInstance->Time(); - if (currtime != lasttime) + const long currtimens = ServerInstance->Time_ns(); + if (currtime != lasttime || currtimens != lasttimens) { lasttime = currtime; - // Cache the string so it's not recreated every time a message is sent - lasttimestring = IRCv3::ServerTime::FormatTime(currtime); + lasttimens = currtimens; + + // Cache the string so it's not recreated every time a message is sent. + lasttimestring = IRCv3::ServerTime::FormatTime(currtime, (currtimens ? currtimens / 1000000 : 0)); } } @@ -42,6 +46,7 @@ class ServerTimeTag : public IRCv3::ServerTime::Manager, public IRCv3::CapTag<Se : IRCv3::ServerTime::Manager(mod) , IRCv3::CapTag<ServerTimeTag>(mod, "server-time", "time") , lasttime(0) + , lasttimens(0) { tagprov = this; }