From a9440b1595be7053b17895f7ee36652bac24be6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Mon, 19 Jan 2026 12:35:16 +0100 Subject: [PATCH] util: add `TicksSeconds` Add a helper to convert durations to integer seconds. --- src/test/util_tests.cpp | 9 +++++++++ src/util/time.h | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index 13821db4b95..e15a489fd5f 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 655db4475a5..fff8c86612f 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(d).count(); } + +template +constexpr int64_t TicksSeconds(Duration d) +{ + return int64_t{Ticks(d)}; +} template constexpr auto TicksSinceEpoch(Timepoint t) {