formatDurationStr()
to use the chrono
standard lib. No change in behavior.
formatDurationStr()
to use the chrono
standard lib. No change in behavior.
ACK 6f2593dc23565abaa3d176595cba6e07883f512e
The updated code looks clean and is straightforward to understand. I was able to compile the PR branch successfully and test that updated formatDurationStr
is providing correct results for the ui->peerConnTime
.
Here is a screenshot of the correct working of the PR.
As a small nit suggestion, I think it would be a good idea to space out the code a little bit into logical sections. But this is a non-critical suggestion, and you may take it up in case you are going to update the PR for some other reasons.
734+ const auto d{std::chrono::duration_cast<days>(dur)};
735+ const auto h{std::chrono::duration_cast<std::chrono::hours>(dur - d)};
736+ const auto m{std::chrono::duration_cast<std::chrono::minutes>(dur - d - h)};
737+ const auto s{std::chrono::duration_cast<std::chrono::seconds>(dur - d - h - m)};
738+ QStringList str_list;
739+ if (auto d2{d.count()}) str_list.append(QObject::tr("%1 d").arg(d2));
738+ QStringList str_list;
739+ if (auto d2{d.count()}) str_list.append(QObject::tr("%1 d").arg(d2));
740+ if (auto h2{h.count()}) str_list.append(QObject::tr("%1 h").arg(h2));
741+ if (auto m2{m.count()}) str_list.append(QObject::tr("%1 m").arg(m2));
742+ const auto s2{s.count()};
743+ if (s2 || str_list.empty()) str_list.append(QObject::tr("%1 s").arg(s2));
6f2593dc23565abaa3d176595cba6e07883f512e
nit, suggestion:
0if (auto s2{s.count()}) str_list.append(QObject::tr("%1 s").arg(s2));
1return str_list.empty() ? "0 s" : str_list.join(" ");
Note: When following up - “Connection Age” will bring the naming convention together - in the gui as well as CL
Code review ACK 6f2593dc23565abaa3d176595cba6e07883f512e.
Maybe leave a comment that <format>
can be used once we jump to C++20.
tACK 6f2593dc23565abaa3d176595cba6e07883f512e
tested on macOS x86_64, Arm64