25#ifdef OPENVPN_PLATFORM_WIN
82 return Duration(std::numeric_limits<T>::max());
89 return Duration(v + (v * T(3) / T(128)));
95 return milliseconds(openvpn::numeric_util::numeric_cast<T>(ms.count()));
113 return duration_ == std::numeric_limits<T>::max();
121 duration_ = std::numeric_limits<T>::max();
144 const unsigned int ndelta = -
delta;
223#define OPENVPN_DURATION_REL(OP) \
224 bool operator OP(const Duration &d) const \
226 return duration_ OP d.duration_; \
234#undef OPENVPN_DURATION_REL
256 return TimeType(std::numeric_limits<T>::max());
268 return time_ == std::numeric_limits<T>::max();
277 time_ = std::numeric_limits<T>::max();
377 const int idf = int(df);
378 if (df ==
static_cast<double>(idf))
385#define OPENVPN_TIME_REL(OP) \
386 bool operator OP(const TimeType &t) const \
388 return time_ OP t.time_; \
396#undef OPENVPN_TIME_REL
398 template <
typename HASH>
415 if (newbase -
base_ >= (60 * 60 * 24 * 30))
422#ifdef OPENVPN_TIME_NO_BASE
423 static_assert(
sizeof(
base_type) >= 8,
"OPENVPN_TIME_NO_BASE requires time_t to be 64 bits");
425 base_ = ::time(NULL);
426#ifdef OPENVPN_PLATFORM_WIN
427 win_recalibrate(::GetTickCount64());
436 return ((11644473600ULL * uint64_t(
prec)) + (uint64_t(
base_) * uint64_t(
prec)) + uint64_t(
now_())) * 78125ULL / 8ULL;
445#ifdef OPENVPN_PLATFORM_WIN
447 static void win_recalibrate(
const ULONGLONG gtc)
450 gtc_base = ::time(NULL) - gtc_last / 1000;
455 const ULONGLONG gtc = ::GetTickCount64();
457 win_recalibrate(gtc);
458 const time_t sec = gtc_base + gtc / 1000;
459 const unsigned int msec = gtc % 1000;
463 static inline ULONGLONG gtc_last = 0;
464 static inline time_t gtc_base = 0;
471 if (::gettimeofday(&tv,
nullptr) != 0)
472 throw get_time_error();
473 return T((tv.tv_sec -
base_) *
prec + tv.tv_usec *
prec / 1000000);
478#ifdef OPENVPN_TIME_NO_BASE
static Duration binary_ms(const T v)
static Duration infinite()
void min(const Duration &d)
Duration(const T duration)
T to_milliseconds() const
void max(const Duration &d)
Duration operator+(const Duration &d) const
Duration & operator+=(const Duration &d)
Duration operator-(const Duration &d) const
Duration operator+(const int delta) const
static Duration milliseconds(std::chrono::milliseconds ms)
Duration & operator-=(const Duration &d)
static Duration milliseconds(const T v)
static Duration seconds(const T v)
Duration operator*(const unsigned int mult) const
static TimeType from_seconds_since_epoch(const time_t t)
std::string delta_str(const TimeType &t) const
TimeType & operator+=(const Duration &d)
static TimeType infinite()
void max(const TimeType &t)
void min(const TimeType &t)
std::uint64_t nanoseconds_since_epoch() const
static uint64_t win_time()
base_type seconds_since_epoch() const
static void reset_base_conditional()
long delta_prec(const TimeType &t) const
Duration operator-(const TimeType &t) const
long delta(const TimeType &t) const
TimeType operator+(const Duration &d) const
double delta_float(const TimeType &t) const
T fractional_binary_ms() const
#define OPENVPN_SIMPLE_EXCEPTION(C)
std::string to_string(const T &t)
Convert a value to a string.
#define OPENVPN_TIME_REL(OP)
#define OPENVPN_DURATION_REL(OP)