From bc25a36972cb319090beb18c99fe40dd857e9452 Mon Sep 17 00:00:00 2001 From: RealKindOne Date: Thu, 1 Oct 2026 15:26:10 -0400 Subject: [PATCH 1/2] listsockets: Fix 1970s date bug. Fixes #1910 --- modules/listsockets.cpp | 16 +++++++++++++--- test/integration/tests/modules.cpp | 12 ++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) 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 From f5c865015c8697ca282b73f6b899eb2ed7347591 Mon Sep 17 00:00:00 2001 From: RealKindOne Date: Thu, 1 Oct 2026 20:00:11 -0400 Subject: [PATCH 2/2] listsockets: Add TODO comment and update test. --- modules/listsockets.cpp | 2 ++ test/integration/tests/modules.cpp | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/listsockets.cpp b/modules/listsockets.cpp index 9790abc5..917dd235 100644 --- a/modules/listsockets.cpp +++ b/modules/listsockets.cpp @@ -155,6 +155,8 @@ class CListSockets : public CModule { unsigned long long iStartTime = pSocket->GetStartTime(); unsigned long long iNow = CUtils::GetMillTime(); + // TODO This code would look simpler with std::chrono instead. + // Especially if socket API is changed to use that. timeval tv = CUtils::GetTime(); unsigned long long iAgeUs = (iNow - iStartTime) * 1000; diff --git a/test/integration/tests/modules.cpp b/test/integration/tests/modules.cpp index 95041926..fe315901 100644 --- a/test/integration/tests/modules.cpp +++ b/test/integration/tests/modules.cpp @@ -1222,8 +1222,11 @@ TEST_F(ZNCTest, ListSocketsModule) { client.Write("znc loadmod listsockets"); client.ReadUntil("Loaded module"); client.Write("PRIVMSG *listsockets :list"); + int year = QDate::currentDate().year(); ASSERT_THAT(client.ReadRemainder().toStdString(), - Not(HasSubstr("1970-"))); + AnyOf(HasSubstr(std::to_string(year - 1) + "-"), + HasSubstr(std::to_string(year) + "-"), + HasSubstr(std::to_string(year + 1) + "-"))); } } // namespace