refactor: gui: Accept up to nanoseconds in formatDurationStr, but clarify they are ignored
What changed, and why it matters
This is a minor code cleanup in Bitcoin Core's graphical user interface. A helper function that turns a time duration into human-readable text now accepts a more precise input type (nanoseconds) but still behaves exactly the same way it did before—any fractional seconds are still ignored. There is no security issue here.
No action needed. This is a non-security refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors GUIUtil::formatDurationStr to take std::chrono::nanoseconds instead of std::chrono::seconds. The implementation already uses duration_cast to days, hours, minutes, and seconds, so sub-second precision is discarded exactly as before. The change is purely ergonomic for future callers and does not alter behavior.
Changed components
src/qt/guiutil.cppsrc/qt/guiutil.hInspect captured patch +3 / −3
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index 9fd46cfc..9cdfe2bc 100644
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -728,7 +728,7 @@ QString ConnectionTypeToQString(ConnectionType conn_type, bool prepend_direction
assert(false);
}
-QString formatDurationStr(std::chrono::seconds dur)
+QString formatDurationStr(std::chrono::nanoseconds dur)
{
const auto d{std::chrono::duration_cast<std::chrono::days>(dur)};
const auto h{std::chrono::duration_cast<std::chrono::hours>(dur - d)};
diff --git a/src/qt/guiutil.h b/src/qt/guiutil.h
index bcde397d..f34c4eac 100644
--- a/src/qt/guiutil.h
+++ b/src/qt/guiutil.h
@@ -228,8 +228,8 @@ namespace GUIUtil
/** Convert enum ConnectionType to QString */
QString ConnectionTypeToQString(ConnectionType conn_type, bool prepend_direction);
- /** Convert seconds into a QString with days, hours, mins, secs */
- QString formatDurationStr(std::chrono::seconds dur);
+ /// Convert a duration into a QString with days, hours, mins, secs. This ignores sub-seconds.
+ QString formatDurationStr(std::chrono::nanoseconds dur);
/** Convert peer connection time to a QString denominated in the most relevant unit. */
QString FormatPeerAge(std::chrono::seconds time_connected);
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.