feat(util): app-wide 24h/12h clock format

Add util::formatClockDateTime/formatClockTime driven by a process-wide flag (setClock12h,
synced from the time_format setting each frame). Switch the primary user-facing timestamp
displays to it — the transaction list, wallet-state tx + banned-peer times, the explorer
block time, and the block-info dialog — so one preference drives every clock.

Log files, export filenames/content, console line prefixes, the market chart axis, and the
worker-thread "last updated" string intentionally stay fixed 24h.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-17 18:44:44 -05:00
parent acde8c0833
commit 8d8cd337cf
6 changed files with 50 additions and 26 deletions

View File

@@ -19,8 +19,38 @@ std::int64_t secondsAgo(std::int64_t timestamp)
std::int64_t diff = now - timestamp;
return diff < 0 ? 0 : diff;
}
bool g_clock12h = false; // app-wide 12-hour clock preference (synced from settings each frame)
} // namespace
void setClock12h(bool enabled) { g_clock12h = enabled; }
bool clock12h() { return g_clock12h; }
std::string formatClockDateTime(std::int64_t timestamp, bool withSeconds)
{
if (timestamp <= 0) return {};
std::time_t t = static_cast<std::time_t>(timestamp);
std::tm* tm = std::localtime(&t); // UI thread only
if (!tm) return {};
const char* fmt = g_clock12h
? (withSeconds ? "%Y-%m-%d %I:%M:%S %p" : "%Y-%m-%d %I:%M %p")
: (withSeconds ? "%Y-%m-%d %H:%M:%S" : "%Y-%m-%d %H:%M");
char buf[40];
return std::strftime(buf, sizeof(buf), fmt, tm) > 0 ? std::string(buf) : std::string();
}
std::string formatClockTime(std::int64_t timestamp, bool withSeconds)
{
if (timestamp <= 0) return {};
std::time_t t = static_cast<std::time_t>(timestamp);
std::tm* tm = std::localtime(&t); // UI thread only
if (!tm) return {};
const char* fmt = g_clock12h
? (withSeconds ? "%I:%M:%S %p" : "%I:%M %p")
: (withSeconds ? "%H:%M:%S" : "%H:%M");
char buf[24];
return std::strftime(buf, sizeof(buf), fmt, tm) > 0 ? std::string(buf) : std::string();
}
std::string formatTimeAgo(std::int64_t timestamp)
{
if (timestamp <= 0) return {};

View File

@@ -14,6 +14,19 @@
namespace dragonx {
namespace util {
// App-wide clock format (24-hour vs 12-hour). Set once per frame by the App from the global
// `time_format` setting (setClock12h); the formatters below read it so a single preference drives
// every user-facing timestamp. The Chat tab resolves its own override separately.
void setClock12h(bool enabled);
bool clock12h();
// Format an epoch timestamp as a local wall-clock date+time honoring the app clock setting:
// 24h -> "YYYY-MM-DD HH:MM[:SS]", 12h -> "YYYY-MM-DD hh:MM[:SS] AM/PM". Empty when ts <= 0.
std::string formatClockDateTime(std::int64_t timestamp, bool withSeconds = false);
// Just the time-of-day portion honoring the clock setting: 24h "HH:MM[:SS]" / 12h "hh:MM[:SS] AM/PM".
std::string formatClockTime(std::int64_t timestamp, bool withSeconds = false);
// Localized relative time, e.g. "5 minutes ago" (via i18n). Empty when timestamp <= 0.
std::string formatTimeAgo(std::int64_t timestamp);