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) {