diff --git a/src/utils/Timer.hpp b/src/utils/Timer.hpp index 786d7b789fb02993e2279f5e557c22423663a4e9..76e135d8c9711596f238b4e50c2c73664df31ca4 100644 --- a/src/utils/Timer.hpp +++ b/src/utils/Timer.hpp @@ -96,7 +96,7 @@ class Timer } Timer& operator=(const Timer&) = default; - Timer& operator=(Timer&&) = default; + Timer& operator=(Timer&&) = default; Timer(const Timer&) = default; Timer(Timer&&) = default; @@ -107,6 +107,10 @@ class Timer m_status{Status::running} {} + Timer(const std::chrono::time_point<std::chrono::high_resolution_clock>& start) + : m_start{start}, m_elapsed_sum{std::chrono::duration<double>::zero()}, m_status{Status::running} + {} + ~Timer() = default; }; diff --git a/tests/test_Timer.cpp b/tests/test_Timer.cpp index c615f9f3ee72e700c6cbf217800ea331b735f569..f0083a477b084861965f4480c7d9750f0c22d128 100644 --- a/tests/test_Timer.cpp +++ b/tests/test_Timer.cpp @@ -59,6 +59,11 @@ TEST_CASE("Timer", "[utils]") t2.reset(); REQUIRE(t2.status() == Timer::Status::paused); REQUIRE(t2.seconds() == 0); + + using namespace std::chrono_literals; + Timer t3{std::chrono::high_resolution_clock::now() - 24h}; + REQUIRE(t3.status() == Timer::Status::running); + REQUIRE(t3.seconds() > 24 * 3600); } SECTION("stop/start")