aboutsummaryrefslogtreecommitdiff
path: root/src/qt/guiutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qt/guiutil.cpp')
-rw-r--r--src/qt/guiutil.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index 362601b512..95b0a390e0 100644
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -80,6 +80,8 @@
void ForceActivation();
#endif
+using namespace std::chrono_literals;
+
namespace GUIUtil {
QString dateTimeStr(const QDateTime &date)
@@ -728,6 +730,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;