util: add TicksSeconds

Add a helper to convert durations to integer seconds.
This commit is contained in:
Lőrinc committed 2026-01-19 12:37:01 +01:00
1 parent 22bde74d1d
commit a9440b1595
2 files changed
+15

No files matched your search

+9
View File
@@ -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);
+6
View File
@@ -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)
{