mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-09 02:59:31 +08:00
util: add TicksSeconds
Add a helper to convert durations to integer seconds.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user