File tree Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,14 @@ template std::chrono::seconds GetTime();
90
90
template std::chrono::milliseconds GetTime ();
91
91
template std::chrono::microseconds GetTime ();
92
92
93
+ template <typename T>
94
+ static T GetSystemTime ()
95
+ {
96
+ const auto now = std::chrono::duration_cast<T>(std::chrono::system_clock::now ().time_since_epoch ());
97
+ assert (now.count () > 0 );
98
+ return now;
99
+ }
100
+
93
101
void SetMockTime (int64_t nMockTimeIn)
94
102
{
95
103
Assert (nMockTimeIn >= 0 );
@@ -103,23 +111,17 @@ int64_t GetMockTime()
103
111
104
112
int64_t GetTimeMillis ()
105
113
{
106
- int64_t now = (boost::posix_time::microsec_clock::universal_time () -
107
- boost::posix_time::ptime (boost::gregorian::date (1970 ,1 ,1 ))).total_milliseconds ();
108
- assert (now > 0 );
109
- return now;
114
+ return int64_t {GetSystemTime<std::chrono::milliseconds>().count ()};
110
115
}
111
116
112
117
int64_t GetTimeMicros ()
113
118
{
114
- int64_t now = (boost::posix_time::microsec_clock::universal_time () -
115
- boost::posix_time::ptime (boost::gregorian::date (1970 ,1 ,1 ))).total_microseconds ();
116
- assert (now > 0 );
117
- return now;
119
+ return int64_t {GetSystemTime<std::chrono::microseconds>().count ()};
118
120
}
119
121
120
122
int64_t GetSystemTimeInSeconds ()
121
123
{
122
- return GetTimeMicros ()/ 1000000 ;
124
+ return int64_t {GetSystemTime<std::chrono::seconds>(). count ()} ;
123
125
}
124
126
125
127
std::string FormatISO8601DateTime (int64_t nTime) {
You can’t perform that action at this time.
0 commit comments