Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14864684
D11790.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
D11790.diff
View Options
diff --git a/src/util/time.cpp b/src/util/time.cpp
--- a/src/util/time.cpp
+++ b/src/util/time.cpp
@@ -89,6 +89,13 @@
template std::chrono::milliseconds GetTime();
template std::chrono::microseconds GetTime();
+template <typename T> static T GetSystemTime() {
+ const auto now = std::chrono::duration_cast<T>(
+ std::chrono::system_clock::now().time_since_epoch());
+ assert(now.count() > 0);
+ return now;
+}
+
void SetMockTime(int64_t nMockTimeIn) {
assert(nMockTimeIn >= 0);
nMockTime.store(nMockTimeIn, std::memory_order_relaxed);
@@ -99,23 +106,15 @@
}
int64_t GetTimeMillis() {
- int64_t now = (boost::posix_time::microsec_clock::universal_time() -
- boost::posix_time::ptime(boost::gregorian::date(1970, 1, 1)))
- .total_milliseconds();
- assert(now > 0);
- return now;
+ return int64_t{GetSystemTime<std::chrono::milliseconds>().count()};
}
int64_t GetTimeMicros() {
- int64_t now = (boost::posix_time::microsec_clock::universal_time() -
- boost::posix_time::ptime(boost::gregorian::date(1970, 1, 1)))
- .total_microseconds();
- assert(now > 0);
- return now;
+ return int64_t{GetSystemTime<std::chrono::microseconds>().count()};
}
int64_t GetTimeSeconds() {
- return GetTimeMicros() / 1000000;
+ return int64_t{GetSystemTime<std::chrono::seconds>().count()};
}
std::string FormatISO8601DateTime(int64_t nTime) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, May 20, 21:36 (18 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5865981
Default Alt Text
D11790.diff (1 KB)
Attached To
D11790: util: Use std::chrono for time getters
Event Timeline
Log In to Comment