What changed, and why it matters
This commit adds a small helper function called TicksSeconds that converts a time duration into whole seconds, along with a few unit tests. It is a routine code cleanup/refactoring change with no security relevance.
No security action required. Treat as normal code maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch introduces a constexpr template function TicksSeconds(Duration d) in src/util/time.h that wraps the existing Ticks
Changed components
src/util/time.hsrc/test/util_tests.cppInspect captured patch +15 / −0
diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp
index 13821db4..e15a489f 100644
--- a/src/test/util_tests.cpp
+++ b/src/test/util_tests.cpp
@@ -585,6 +585,15 @@ BOOST_AUTO_TEST_CASE(util_mocktime)
SetMockTime(0s);
}
+BOOST_AUTO_TEST_CASE(util_ticksseconds)
+{
+ BOOST_CHECK_EQUAL(TicksSeconds(0s), 0);
+ BOOST_CHECK_EQUAL(TicksSeconds(1s), 1);
+ BOOST_CHECK_EQUAL(TicksSeconds(999ms), 0);
+ BOOST_CHECK_EQUAL(TicksSeconds(1000ms), 1);
+ BOOST_CHECK_EQUAL(TicksSeconds(1500ms), 1);
+}
+
BOOST_AUTO_TEST_CASE(test_IsDigit)
{
BOOST_CHECK_EQUAL(IsDigit('0'), true);
diff --git a/src/util/time.h b/src/util/time.h
index 655db447..fff8c866 100644
--- a/src/util/time.h
+++ b/src/util/time.h
@@ -74,6 +74,12 @@ constexpr auto Ticks(Dur2 d)
{
return std::chrono::duration_cast<Dur1>(d).count();
}
+
+template <typename Duration>
+constexpr int64_t TicksSeconds(Duration d)
+{
+ return int64_t{Ticks<std::chrono::seconds>(d)};
+}
template <typename Duration, typename Timepoint>
constexpr auto TicksSinceEpoch(Timepoint t)
{
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.