diff --git a/README.md b/README.md index 3282dabe..dc584206 100644 --- a/README.md +++ b/README.md @@ -259,6 +259,7 @@ This configuration file holds general application settings. Default content: proxy_pass= proxy_port= proxy_user= + timestamp_iso=0 ### attachment_send_type @@ -292,6 +293,18 @@ time, it is recommended to first run nchat without arguments (`nchat`) for its config dir to be created, and then edit proxy settings in `~/.nchat/app.conf` as needed, before running `nchat -s` to setup an account. +### timestamp_iso + +Specifies whether to use ISO-style timestamps (`YYYY-MM-DD HH:MM`) in the UI +and at export of chat history. By default nchat uses a dynamic "human-friendly" +format: + +- `HH:MM` for timestamps on same date as today, e.g. `19:00` +- `DAY HH:MM` for timestamps in the last week, e.g. `Mon 19:00` +- `DD MMM HH:MM` for timestamps in the current year, e.g. `14 Nov 19:00` +- `DD MMM YYYY HH:MM` for timestamps in non-current year, e.g. `14 Nov 2022 19:00` +- `DD MMM YYYY HH:MM` for timestamps during export, e.g. `14 Nov 2022 19:00` + ~/.nchat/ui.conf ---------------- This configuration file holds general user interface settings. Default content: diff --git a/lib/common/src/version.h b/lib/common/src/version.h index 0b7138a4..18829baf 100644 --- a/lib/common/src/version.h +++ b/lib/common/src/version.h @@ -7,4 +7,4 @@ #pragma once -#define NCHAT_VERSION "4.07" +#define NCHAT_VERSION "4.08" diff --git a/lib/ncutil/src/appconfig.cpp b/lib/ncutil/src/appconfig.cpp index f138723d..48d12275 100644 --- a/lib/ncutil/src/appconfig.cpp +++ b/lib/ncutil/src/appconfig.cpp @@ -26,6 +26,7 @@ void AppConfig::Init() { "proxy_pass", "" }, { "proxy_port", "" }, { "proxy_user", "" }, + { "timestamp_iso", "0" }, }; const std::string configPath(FileUtil::GetApplicationDir() + std::string("/app.conf")); diff --git a/lib/ncutil/src/messagecache.cpp b/lib/ncutil/src/messagecache.cpp index f0335d9c..129febca 100644 --- a/lib/ncutil/src/messagecache.cpp +++ b/lib/ncutil/src/messagecache.cpp @@ -594,7 +594,7 @@ void MessageCache::Export(const std::string& p_ExportDir) std::map messageMap; for (auto chatMessage = chatMessages.rbegin(); chatMessage != chatMessages.rend(); ++chatMessage) { - std::string timestr = TimeUtil::GetTimeString(chatMessage->timeSent, false /* p_Short */); + std::string timestr = TimeUtil::GetTimeString(chatMessage->timeSent, true /* p_IsExport */); std::string year = TimeUtil::GetYearString(chatMessage->timeSent);; if (year != lastYear) { diff --git a/lib/ncutil/src/timeutil.cpp b/lib/ncutil/src/timeutil.cpp index 202f2e05..81ff4bb1 100644 --- a/lib/ncutil/src/timeutil.cpp +++ b/lib/ncutil/src/timeutil.cpp @@ -13,6 +13,8 @@ #include +#include "appconfig.h" + int64_t TimeUtil::GetCurrentTimeMSec() { struct timeval now; @@ -20,7 +22,7 @@ int64_t TimeUtil::GetCurrentTimeMSec() return static_cast((now.tv_sec * 1000) + (now.tv_usec / 1000)); } -std::string TimeUtil::GetTimeString(int64_t p_TimeSent, bool p_Short) +std::string TimeUtil::GetTimeString(int64_t p_TimeSent, bool p_IsExport) { time_t timeSent = (time_t)(p_TimeSent / 1000); struct tm tmSent; @@ -30,8 +32,18 @@ std::string TimeUtil::GetTimeString(int64_t p_TimeSent, bool p_Short) localtime_r(&timeNow, &tmNow); char tmpstr[32] = { 0 }; static int64_t useWeekdayMaxAge = (6 * 24 * 3600); + static bool isTimestampIso = AppConfig::GetBool("timestamp_iso"); - if (p_Short) + if (isTimestampIso) + { + strftime(tmpstr, sizeof(tmpstr), "%Y-%m-%d %H:%M", &tmSent); + } + else if (p_IsExport) + { + int dlen = snprintf(tmpstr, sizeof(tmpstr), "%d ", tmSent.tm_mday); + strftime(tmpstr + dlen, sizeof(tmpstr) - dlen, "%b %Y %H:%M", &tmSent); + } + else { if ((tmSent.tm_year == tmNow.tm_year) && (tmSent.tm_mon == tmNow.tm_mon) && (tmSent.tm_mday == tmNow.tm_mday)) { @@ -52,11 +64,6 @@ std::string TimeUtil::GetTimeString(int64_t p_TimeSent, bool p_Short) strftime(tmpstr + dlen, sizeof(tmpstr) - dlen, "%b %Y %H:%M", &tmSent); } } - else - { - int dlen = snprintf(tmpstr, sizeof(tmpstr), "%d ", tmSent.tm_mday); - strftime(tmpstr + dlen, sizeof(tmpstr) - dlen, "%b %Y %H:%M", &tmSent); - } return std::string(tmpstr); } diff --git a/lib/ncutil/src/timeutil.h b/lib/ncutil/src/timeutil.h index e4936260..bbb678d2 100644 --- a/lib/ncutil/src/timeutil.h +++ b/lib/ncutil/src/timeutil.h @@ -14,7 +14,7 @@ class TimeUtil { public: static int64_t GetCurrentTimeMSec(); - static std::string GetTimeString(int64_t p_TimeSent, bool p_Short); + static std::string GetTimeString(int64_t p_TimeSent, bool p_IsExport); static std::string GetYearString(int64_t p_TimeSent); static void Sleep(double p_Sec); }; diff --git a/src/nchat.1 b/src/nchat.1 index a9f1b0cf..c3e218e5 100644 --- a/src/nchat.1 +++ b/src/nchat.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man. -.TH NCHAT "1" "November 2023" "nchat v4.07" "User Commands" +.TH NCHAT "1" "December 2023" "nchat v4.08" "User Commands" .SH NAME nchat \- ncurses chat .SH SYNOPSIS diff --git a/src/uihistoryview.cpp b/src/uihistoryview.cpp index b63c1917..77c13e4d 100644 --- a/src/uihistoryview.cpp +++ b/src/uihistoryview.cpp @@ -1,6 +1,6 @@ // uihistoryview.cpp // -// Copyright (c) 2019-2021 Kristofer Berggren +// Copyright (c) 2019-2023 Kristofer Berggren // All rights reserved. // // nchat is distributed under the MIT license, see LICENSE for details. @@ -291,7 +291,7 @@ void UiHistoryView::Draw() std::wstring wtime; if (msg.timeSent != std::numeric_limits::max()) { - wtime = L" (" + StrUtil::ToWString(TimeUtil::GetTimeString(msg.timeSent, true /* p_Short */)) + L")"; + wtime = L" (" + StrUtil::ToWString(TimeUtil::GetTimeString(msg.timeSent, false /* p_IsExport */)) + L")"; } if (!msg.isOutgoing && !msg.isRead) diff --git a/src/uimodel.cpp b/src/uimodel.cpp index 7a6b3cfc..7053010c 100644 --- a/src/uimodel.cpp +++ b/src/uimodel.cpp @@ -2176,7 +2176,7 @@ std::string UiModel::GetChatStatus(const std::string& p_ProfileId, const std::st break; default: - chatStatus = "seen " + TimeUtil::GetTimeString(timeSeen, true /* p_Short */); + chatStatus = "seen " + TimeUtil::GetTimeString(timeSeen, false /* p_IsExport */); break; } }