From 2720c161c933f9dbb5aa4fa87b67bf215d67a026 Mon Sep 17 00:00:00 2001 From: Fedja Beader Date: Wed, 11 Oct 2023 23:10:24 +0200 Subject: Use gmtime() for non-local-time chat timestamps --- src/gui/widgets/tabs/chat/chattab.cpp | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/src/gui/widgets/tabs/chat/chattab.cpp b/src/gui/widgets/tabs/chat/chattab.cpp index 52ec7fb4f..48c0669fc 100644 --- a/src/gui/widgets/tabs/chat/chattab.cpp +++ b/src/gui/widgets/tabs/chat/chattab.cpp @@ -246,32 +246,19 @@ void ChatTab::chatLog(std::string line, time_t t; time(&t); - if (config.getBoolValue("useLocalTime")) + const tm* const timeInfo = + config.getBoolValue("useLocalTime") ? localtime(&t) : gmtime(&t); + + if (timeInfo != nullptr) { - const tm *const timeInfo = localtime(&t); - if (timeInfo != nullptr) - { - line = strprintf("%s[%02d:%02d] %s%s", lineColor.c_str(), - timeInfo->tm_hour, timeInfo->tm_min, tmp.nick.c_str(), - tmp.text.c_str()); - } - else - { - line = strprintf("%s %s%s", lineColor.c_str(), - tmp.nick.c_str(), tmp.text.c_str()); - } + line = strprintf("%s[%02d:%02d] %s%s", lineColor.c_str(), + timeInfo->tm_hour, timeInfo->tm_min, + tmp.nick.c_str(), tmp.text.c_str()); } else { - // Format the time string properly - std::stringstream timeStr; - timeStr << "[" << ((((t / 60) / 60) % 24 < 10) ? "0" : "") - << CAST_S32(((t / 60) / 60) % 24) - << ":" << (((t / 60) % 60 < 10) ? "0" : "") - << CAST_S32((t / 60) % 60) - << "] "; - line = std::string(lineColor).append(timeStr.str()).append( - tmp.nick).append(tmp.text); + line = strprintf("%s %s%s", lineColor.c_str(), + tmp.nick.c_str(), tmp.text.c_str()); } if (config.getBoolValue("enableChatLog")) -- cgit v1.2.3-60-g2f50