diff options
author | Jon Atack <jon@atack.com> | 2022-02-13 19:44:05 +0100 |
---|---|---|
committer | randymcmillan <randy.lee.mcmillan@gmail.com> | 2022-03-16 04:54:52 -0400 |
commit | 127de22c5fb396e1670d2a911faf7a9adc9241e2 (patch) | |
tree | fd85c94e87d4dc72b6a9d71b1fdc4e82aed5258d /src/qt/guiutil.cpp | |
parent | 310ba924949b0052105a7937ac69d65a3864692b (diff) |
gui: add FormatPeerAge() utility helper
Co-authored-by: randymcmillan <randy.lee.mcmillan@gmail.com>
Diffstat (limited to 'src/qt/guiutil.cpp')
-rw-r--r-- | src/qt/guiutil.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 3108c93d7c..130f424e43 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -79,6 +79,8 @@ void ForceActivation(); #endif +using namespace std::chrono_literals; + namespace GUIUtil { QString dateTimeStr(const QDateTime &date) @@ -727,6 +729,16 @@ QString formatDurationStr(std::chrono::seconds dur) return str_list.join(" "); } +QString FormatPeerAge(std::chrono::seconds time_connected) +{ + const auto time_now{GetTime<std::chrono::seconds>()}; + const auto age{time_now - time_connected}; + if (age >= 24h) return QObject::tr("%1 d").arg(age / 24h); + if (age >= 1h) return QObject::tr("%1 h").arg(age / 1h); + if (age >= 1min) return QObject::tr("%1 m").arg(age / 1min); + return QObject::tr("%1 s").arg(age / 1s); +} + QString formatServicesStr(quint64 mask) { QStringList strList; |