mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-31 09:41:06 +02:00
gui: add FormatPeerAge() utility helper
Co-authored-by: randymcmillan <randy.lee.mcmillan@gmail.com>
This commit is contained in:
@@ -79,6 +79,8 @@
|
|||||||
void ForceActivation();
|
void ForceActivation();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
namespace GUIUtil {
|
namespace GUIUtil {
|
||||||
|
|
||||||
QString dateTimeStr(const QDateTime &date)
|
QString dateTimeStr(const QDateTime &date)
|
||||||
@@ -727,6 +729,16 @@ QString formatDurationStr(std::chrono::seconds dur)
|
|||||||
return str_list.join(" ");
|
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)
|
QString formatServicesStr(quint64 mask)
|
||||||
{
|
{
|
||||||
QStringList strList;
|
QStringList strList;
|
||||||
|
@@ -223,6 +223,9 @@ namespace GUIUtil
|
|||||||
/** Convert seconds into a QString with days, hours, mins, secs */
|
/** Convert seconds into a QString with days, hours, mins, secs */
|
||||||
QString formatDurationStr(std::chrono::seconds dur);
|
QString formatDurationStr(std::chrono::seconds dur);
|
||||||
|
|
||||||
|
/** Convert peer connection time to a QString denominated in the most relevant unit. */
|
||||||
|
QString FormatPeerAge(std::chrono::seconds time_connected);
|
||||||
|
|
||||||
/** Format CNodeStats.nServices bitmask into a user-readable string */
|
/** Format CNodeStats.nServices bitmask into a user-readable string */
|
||||||
QString formatServicesStr(quint64 mask);
|
QString formatServicesStr(quint64 mask);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user