add unix_nano_now() to datetime.h

This commit is contained in:
Eric Harding committed 2020-02-14 16:05:00 -06:00
1 parent 8d6d8cab18
commit 385f3ea402
2 files changed
+12

No files matched your search

+11
View File
@@ -44,6 +44,17 @@ LLDateTime ll_local_now() {
long unix_now() {
return (boost::posix_time::microsec_clock::universal_time() - PTime(anchor)).total_microseconds() / (long)1E6;
}
#ifndef _WIN32
uint64_t unix_nano_now() {
struct timespec ts;
// CLOCK_REALTIME is already anchored at the unix epoch
clock_gettime(CLOCK_REALTIME, &ts);
return
static_cast<int64_t>(1000000000UL)*
static_cast<int64_t>(ts.tv_sec) +
static_cast<int64_t>(ts.tv_nsec);
}
#endif
std::chrono::system_clock::time_point utc_ll_to_timepoint(unsigned long long ll) {
auto us_since_epoch = ((ll & ticks_mask) - anchor_ticks) / ticks_per_micro;
+1
View File
@@ -41,6 +41,7 @@ extern "C" BTS_EXPORT LLDateTime ll_local_now ();
extern "C" BTS_EXPORT double OA_date_from_ll (LLDateTime ll);
extern "C" BTS_EXPORT LLDateTime ll_from_OA_date (double oa_date);
extern "C" BTS_EXPORT long unix_now();
uint64_t unix_nano_now();
BTS_EXPORT std::chrono::system_clock::time_point utc_ll_to_timepoint(unsigned long long ll) ;
BTS_EXPORT PTime now ();