aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/time_provider/time_provider.cpp
blob: 6c1ba8e07c9024c6ae64f19054758399885078f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "time_provider.h"

class TDefaultTimeProvider: public ITimeProvider {
public:
    TInstant Now() override {
        return TInstant::Now();
    }
};

class TDeterministicTimeProvider: public ITimeProvider {
public:
    TDeterministicTimeProvider(ui64 seed) {
        Value = TInstant::Seconds(seed);
    }

    TInstant Now() override {
        return Value;
    }

private:
    TInstant Value;
};

TIntrusivePtr<ITimeProvider> CreateDefaultTimeProvider() {
    return TIntrusivePtr<ITimeProvider>(new TDefaultTimeProvider());
}

TIntrusivePtr<ITimeProvider> CreateDeterministicTimeProvider(ui64 seed) {
    return TIntrusivePtr<ITimeProvider>(new TDeterministicTimeProvider(seed));
}