blob: 3871a3bd20c1ffa307687c9e14fc4904810c1b6a [file] [log] [blame]
Krzysztof Grobelny80697712021-03-04 09:49:27 +00001#pragma once
2
3#include "interfaces/clock.hpp"
4#include "types/duration_type.hpp"
5
6class ClockFake : public interfaces::Clock
7{
8 public:
9 time_point now() const noexcept override
10 {
11 return timePoint;
12 }
13
14 uint64_t timestamp() const noexcept override
15 {
16 return toTimestamp(now());
17 }
18
19 uint64_t advance(Milliseconds delta) noexcept
20 {
21 timePoint += delta;
22 return timestamp();
23 }
24
25 void set(Milliseconds timeSinceEpoch) noexcept
26 {
27 timePoint = time_point{timeSinceEpoch};
28 }
29
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020030 void reset(void) noexcept
31 {
32 set(Milliseconds(0));
33 }
34
Krzysztof Grobelny80697712021-03-04 09:49:27 +000035 static uint64_t toTimestamp(Milliseconds time)
36 {
37 return time.count();
38 }
39
40 static uint64_t toTimestamp(time_point tp)
41 {
42 return std::chrono::time_point_cast<Milliseconds>(tp)
43 .time_since_epoch()
44 .count();
45 }
46
47 private:
48 time_point timePoint = std::chrono::steady_clock::now();
49};