From 385f3ea4026f3520d3eefbc6f70d06f8ad4de1e4 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Thu, 13 Feb 2020 15:05:17 -0600 Subject: [PATCH] add unix_nano_now() to datetime.h --- src/lib/utils/datetime.cpp | 11 +++++++++++ src/lib/utils/datetime.h | 1 + 2 files changed, 12 insertions(+) diff --git a/src/lib/utils/datetime.cpp b/src/lib/utils/datetime.cpp index 9fb4db93f..83eafe3fb 100755 --- a/src/lib/utils/datetime.cpp +++ b/src/lib/utils/datetime.cpp @@ -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(1000000000UL)* + static_cast(ts.tv_sec) + + static_cast(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; diff --git a/src/lib/utils/datetime.h b/src/lib/utils/datetime.h index 62384ed69..8cb63979d 100755 --- a/src/lib/utils/datetime.h +++ b/src/lib/utils/datetime.h @@ -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 ();