aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/time_provider/time_provider.cpp
blob: c3181856f85c08ef35f0e9f5eed75334be579ca0 (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)); 
}