summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFedja Beader <fedja@protonmail.ch>2023-10-11 23:43:00 +0200
committerFedja Beader <fedja@protonmail.ch>2023-10-13 00:06:45 +0200
commit5dda53c71f51ab46e273a6c3033925102cbe99e7 (patch)
tree3855348772594d138a77e9042a52be32cf9cbdd1
parent2720c161c933f9dbb5aa4fa87b67bf215d67a026 (diff)
downloadplus-5dda53c71f51ab46e273a6c3033925102cbe99e7.tar.gz
plus-5dda53c71f51ab46e273a6c3033925102cbe99e7.tar.bz2
plus-5dda53c71f51ab46e273a6c3033925102cbe99e7.tar.xz
plus-5dda53c71f51ab46e273a6c3033925102cbe99e7.zip
Use strftime to format timestamps.
+Provide visible fallbacks if either strftime or gmtime/localtime failed. Appease mplint
-rw-r--r--src/gui/widgets/tabs/chat/chattab.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/gui/widgets/tabs/chat/chattab.cpp b/src/gui/widgets/tabs/chat/chattab.cpp
index 48c0669fc..f619a881c 100644
--- a/src/gui/widgets/tabs/chat/chattab.cpp
+++ b/src/gui/widgets/tabs/chat/chattab.cpp
@@ -251,13 +251,27 @@ void ChatTab::chatLog(std::string line,
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());
+ char timeStamp[64]; // 64 bytes should be enough for everybody?? C..
+
+ size_t res = strftime(timeStamp, 64, "[%H:%M]", timeInfo);
+ // strftime returns 0 even in case of success (empty format or %p)
+ // see strftime(3) for further details.
+ if (res > 0)
+ {
+ line = strprintf("%s%s %s%s", lineColor.c_str(), timeStamp,
+ tmp.nick.c_str(), tmp.text.c_str());
+ }
+ else
+ {
+ line = strprintf("%s[(strftime error)%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(),
+ line = strprintf("(local/gm-time error)%s %s%s", lineColor.c_str(),
tmp.nick.c_str(), tmp.text.c_str());
}