-
Notifications
You must be signed in to change notification settings - Fork 337
refactor: use std::chrono for formatDurationStr() helper #549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, suggestion: if (auto s2{s.count()}) str_list.append(QObject::tr("%1 s").arg(s2));
return str_list.empty() ? "0 s" : str_list.join(" ");
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, will do if have to retouch or will sneak it into the translator comments follow-up.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: When following up - "Connection Age" will bring the naming convention together - in the gui as well as CL |
||
| return str_list.join(" "); | ||
| } | ||
|
|
||
| QString formatServicesStr(quint64 mask) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add translator comments, here and after?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, doing for several of these (FormatPeerAge, formatDurationStr, TimeDurationField, etc.) as a follow-up to this and to #543 (see #543 (comment)). That way this remains a straight refactor and current review on both pulls isn't invalidated.