0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-13 11:25:02 -05:00

gui, refactor: use std::chrono for formatDurationStr() helper

This commit is contained in:
Jon Atack 2022-02-14 21:02:50 +01:00
parent 8fe6f5a6fb
commit 6f2593dc23
No known key found for this signature in database
GPG key ID: 796C4109063D4EAF

View file

@ -713,23 +713,18 @@ QString ConnectionTypeToQString(ConnectionType conn_type, bool prepend_direction
QString formatDurationStr(std::chrono::seconds dur) QString formatDurationStr(std::chrono::seconds dur)
{ {
const auto secs = count_seconds(dur); using days = std::chrono::duration<int, std::ratio<86400>>; // can remove this line after C++20
QStringList strList; const auto d{std::chrono::duration_cast<days>(dur)};
int days = secs / 86400; const auto h{std::chrono::duration_cast<std::chrono::hours>(dur - d)};
int hours = (secs % 86400) / 3600; const auto m{std::chrono::duration_cast<std::chrono::minutes>(dur - d - h)};
int mins = (secs % 3600) / 60; const auto s{std::chrono::duration_cast<std::chrono::seconds>(dur - d - h - m)};
int seconds = secs % 60; QStringList str_list;
if (auto d2{d.count()}) str_list.append(QObject::tr("%1 d").arg(d2));
if (days) if (auto h2{h.count()}) str_list.append(QObject::tr("%1 h").arg(h2));
strList.append(QObject::tr("%1 d").arg(days)); if (auto m2{m.count()}) str_list.append(QObject::tr("%1 m").arg(m2));
if (hours) const auto s2{s.count()};
strList.append(QObject::tr("%1 h").arg(hours)); if (s2 || str_list.empty()) str_list.append(QObject::tr("%1 s").arg(s2));
if (mins) return str_list.join(" ");
strList.append(QObject::tr("%1 m").arg(mins));
if (seconds || (!days && !hours && !mins))
strList.append(QObject::tr("%1 s").arg(seconds));
return strList.join(" ");
} }
QString formatServicesStr(quint64 mask) QString formatServicesStr(quint64 mask)