diff --git a/modules/listsockets.cpp b/modules/listsockets.cpp index ea204560..9790abc5 100644 --- a/modules/listsockets.cpp +++ b/modules/listsockets.cpp @@ -153,9 +153,19 @@ class CListSockets : public CModule { CString GetCreatedTime(const Csock* pSocket) { unsigned long long iStartTime = pSocket->GetStartTime(); - timeval tv; - tv.tv_sec = iStartTime / 1000; - tv.tv_usec = iStartTime % 1000 * 1000; + unsigned long long iNow = CUtils::GetMillTime(); + + timeval tv = CUtils::GetTime(); + unsigned long long iAgeUs = (iNow - iStartTime) * 1000; + + tv.tv_sec -= iAgeUs / 1000000; + long long usec = tv.tv_usec - (long long)(iAgeUs % 1000000); + if (usec < 0) { + tv.tv_sec--; + usec += 1000000; + } + tv.tv_usec = usec; + return CUtils::FormatTime(tv, "%Y-%m-%d %H:%M:%S.%f", GetUser()->GetTimezone()); } diff --git a/test/integration/tests/modules.cpp b/test/integration/tests/modules.cpp index 6bbe49c7..95041926 100644 --- a/test/integration/tests/modules.cpp +++ b/test/integration/tests/modules.cpp @@ -1214,5 +1214,17 @@ TEST_F(ZNCTest, AwayStoreModule) { // End 'away' bug test } +// https://github.com/znc/znc/issues/1910 +TEST_F(ZNCTest, ListSocketsModule) { + auto znc = Run(); + auto ircd = ConnectIRCd(); + auto client = LoginClient(); + client.Write("znc loadmod listsockets"); + client.ReadUntil("Loaded module"); + client.Write("PRIVMSG *listsockets :list"); + ASSERT_THAT(client.ReadRemainder().toStdString(), + Not(HasSubstr("1970-"))); +} + } // namespace } // namespace znc_inttest