util: add TicksSeconds
Add a helper to convert durations to integer seconds.
This commit is contained in:
2 files changed
+15
No files matched your search
@@ -585,6 +585,15 @@ BOOST_AUTO_TEST_CASE(util_mocktime)
|
|||||||
SetMockTime(0s);
|
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_AUTO_TEST_CASE(test_IsDigit)
|
||||||
{
|
{
|
||||||
BOOST_CHECK_EQUAL(IsDigit('0'), true);
|
BOOST_CHECK_EQUAL(IsDigit('0'), true);
|
||||||
|
|||||||
@@ -74,6 +74,12 @@ constexpr auto Ticks(Dur2 d)
|
|||||||
{
|
{
|
||||||
return std::chrono::duration_cast<Dur1>(d).count();
|
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>
|
template <typename Duration, typename Timepoint>
|
||||||
constexpr auto TicksSinceEpoch(Timepoint t)
|
constexpr auto TicksSinceEpoch(Timepoint t)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user