Merge pull request #2047 from RealKindOne/fix-listsockets

listsockets: Fix 1970s date bug.
This commit is contained in:
Alexey Sokolov authored and GitHub committed 2026-10-02 01:43:31 +01:00
commit 3f67acfc4b
2 files changed
+30 -3

No files matched your search

+15 -3
View File
@@ -153,9 +153,21 @@ 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();
// 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;
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());
}
+15
View File
@@ -1214,5 +1214,20 @@ 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");
int year = QDate::currentDate().year();
ASSERT_THAT(client.ReadRemainder().toStdString(),
AnyOf(HasSubstr(std::to_string(year - 1) + "-"),
HasSubstr(std::to_string(year) + "-"),
HasSubstr(std::to_string(year + 1) + "-")));
}
} // namespace
} // namespace znc_inttest