aboutsummaryrefslogtreecommitdiff
path: root/src/qt
diff options
context:
space:
mode:
authorHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2022-03-05 17:18:59 +0100
committerHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2022-03-05 17:20:55 +0100
commitc8f2817bd6b8eb57ba377d7cbc5469c6866822c6 (patch)
tree965908f75c725df4e629c6d72186cb7bfe63afbd /src/qt
parentcc70f65d212ba282f862f860622e2a987703f7ac (diff)
parent6f2593dc23565abaa3d176595cba6e07883f512e (diff)
Merge bitcoin-core/gui#549: refactor: use std::chrono for formatDurationStr() helper
6f2593dc23565abaa3d176595cba6e07883f512e gui, refactor: use std::chrono for formatDurationStr() helper (Jon Atack) Pull request description: Updates `formatDurationStr()` to use the `chrono` standard lib. No change in behavior. ACKs for top commit: RandyMcMillan: tACK 6f2593dc23565abaa3d176595cba6e07883f512e shaavan: ACK 6f2593dc23565abaa3d176595cba6e07883f512e w0xlt: tACK 6f2593d on Ubuntu 21.10 Qt 5.15.2 promag: Code review ACK 6f2593dc23565abaa3d176595cba6e07883f512e. Tree-SHA512: 61e9afdb1db779150df338e6af08727c34f69639add465c2f7003ff775d97dce3e78e78d325bc6dea5bc13f0fce9ef1c3506d13f1661a5e083e52bba8a32ba44
Diffstat (limited to 'src/qt')
-rw-r--r--src/qt/guiutil.cpp29
1 files changed, 12 insertions, 17 deletions
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index 9565fa508f..d6706fd009 100644
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -713,23 +713,18 @@ QString ConnectionTypeToQString(ConnectionType conn_type, bool prepend_direction
QString formatDurationStr(std::chrono::seconds dur)
{
- const auto secs = count_seconds(dur);
- QStringList strList;
- int days = secs / 86400;
- int hours = (secs % 86400) / 3600;
- int mins = (secs % 3600) / 60;
- int seconds = secs % 60;
-
- if (days)
- strList.append(QObject::tr("%1 d").arg(days));
- if (hours)
- strList.append(QObject::tr("%1 h").arg(hours));
- if (mins)
- strList.append(QObject::tr("%1 m").arg(mins));
- if (seconds || (!days && !hours && !mins))
- strList.append(QObject::tr("%1 s").arg(seconds));
-
- return strList.join(" ");
+ using days = std::chrono::duration<int, std::ratio<86400>>; // can remove this line after C++20
+ const auto d{std::chrono::duration_cast<days>(dur)};
+ const auto h{std::chrono::duration_cast<std::chrono::hours>(dur - d)};
+ const auto m{std::chrono::duration_cast<std::chrono::minutes>(dur - d - h)};
+ const auto s{std::chrono::duration_cast<std::chrono::seconds>(dur - d - h - m)};
+ QStringList str_list;
+ if (auto d2{d.count()}) str_list.append(QObject::tr("%1 d").arg(d2));
+ if (auto h2{h.count()}) str_list.append(QObject::tr("%1 h").arg(h2));
+ if (auto m2{m.count()}) str_list.append(QObject::tr("%1 m").arg(m2));
+ const auto s2{s.count()};
+ if (s2 || str_list.empty()) str_list.append(QObject::tr("%1 s").arg(s2));
+ return str_list.join(" ");
}
QString formatServicesStr(quint64 mask)