18069771cSKrzysztof Grobelny #pragma once
28069771cSKrzysztof Grobelny 
38069771cSKrzysztof Grobelny #include "interfaces/clock.hpp"
48069771cSKrzysztof Grobelny #include "types/duration_type.hpp"
58069771cSKrzysztof Grobelny 
68069771cSKrzysztof Grobelny class ClockFake : public interfaces::Clock
78069771cSKrzysztof Grobelny {
88069771cSKrzysztof Grobelny   public:
98069771cSKrzysztof Grobelny     time_point now() const noexcept override
108069771cSKrzysztof Grobelny     {
118069771cSKrzysztof Grobelny         return timePoint;
128069771cSKrzysztof Grobelny     }
138069771cSKrzysztof Grobelny 
148069771cSKrzysztof Grobelny     uint64_t timestamp() const noexcept override
158069771cSKrzysztof Grobelny     {
168069771cSKrzysztof Grobelny         return toTimestamp(now());
178069771cSKrzysztof Grobelny     }
188069771cSKrzysztof Grobelny 
198069771cSKrzysztof Grobelny     uint64_t advance(Milliseconds delta) noexcept
208069771cSKrzysztof Grobelny     {
218069771cSKrzysztof Grobelny         timePoint += delta;
228069771cSKrzysztof Grobelny         return timestamp();
238069771cSKrzysztof Grobelny     }
248069771cSKrzysztof Grobelny 
258069771cSKrzysztof Grobelny     void set(Milliseconds timeSinceEpoch) noexcept
268069771cSKrzysztof Grobelny     {
278069771cSKrzysztof Grobelny         timePoint = time_point{timeSinceEpoch};
288069771cSKrzysztof Grobelny     }
298069771cSKrzysztof Grobelny 
30*7e098e93SLukasz Kazmierczak     void reset(void) noexcept
31*7e098e93SLukasz Kazmierczak     {
32*7e098e93SLukasz Kazmierczak         set(Milliseconds(0));
33*7e098e93SLukasz Kazmierczak     }
34*7e098e93SLukasz Kazmierczak 
358069771cSKrzysztof Grobelny     static uint64_t toTimestamp(Milliseconds time)
368069771cSKrzysztof Grobelny     {
378069771cSKrzysztof Grobelny         return time.count();
388069771cSKrzysztof Grobelny     }
398069771cSKrzysztof Grobelny 
408069771cSKrzysztof Grobelny     static uint64_t toTimestamp(time_point tp)
418069771cSKrzysztof Grobelny     {
428069771cSKrzysztof Grobelny         return std::chrono::time_point_cast<Milliseconds>(tp)
438069771cSKrzysztof Grobelny             .time_since_epoch()
448069771cSKrzysztof Grobelny             .count();
458069771cSKrzysztof Grobelny     }
468069771cSKrzysztof Grobelny 
478069771cSKrzysztof Grobelny   private:
488069771cSKrzysztof Grobelny     time_point timePoint = std::chrono::steady_clock::now();
498069771cSKrzysztof Grobelny };
50