File tree Expand file tree Collapse file tree 1 file changed +6
-13
lines changed Expand file tree Collapse file tree 1 file changed +6
-13
lines changed Original file line number Diff line number Diff line change @@ -23,16 +23,6 @@ void UninterruptibleSleep(const std::chrono::microseconds& n) { std::this_thread
23
23
24
24
static std::atomic<int64_t > nMockTime (0 ); // !< For testing
25
25
26
- int64_t GetTime ()
27
- {
28
- int64_t mocktime = nMockTime.load (std::memory_order_relaxed);
29
- if (mocktime) return mocktime;
30
-
31
- time_t now = time (nullptr );
32
- assert (now > 0 );
33
- return now;
34
- }
35
-
36
26
bool ChronoSanityCheck ()
37
27
{
38
28
// std::chrono::system_clock.time_since_epoch and time_t(0) are not guaranteed
@@ -80,11 +70,12 @@ template <typename T>
80
70
T GetTime ()
81
71
{
82
72
const std::chrono::seconds mocktime{nMockTime.load (std::memory_order_relaxed)};
83
-
84
- return std::chrono::duration_cast<T>(
73
+ const auto ret{
85
74
mocktime.count () ?
86
75
mocktime :
87
- std::chrono::microseconds{GetTimeMicros ()});
76
+ std::chrono::duration_cast<T>(std::chrono::system_clock::now ().time_since_epoch ())};
77
+ assert (ret > 0s);
78
+ return ret;
88
79
}
89
80
template std::chrono::seconds GetTime ();
90
81
template std::chrono::milliseconds GetTime ();
@@ -129,6 +120,8 @@ int64_t GetTimeSeconds()
129
120
return int64_t {GetSystemTime<std::chrono::seconds>().count ()};
130
121
}
131
122
123
+ int64_t GetTime () { return GetTime<std::chrono::seconds>().count (); }
124
+
132
125
std::string FormatISO8601DateTime (int64_t nTime) {
133
126
struct tm ts;
134
127
time_t time_val = nTime;
You can’t perform that action at this time.
0 commit comments