37 #ifndef FIX8_TICKVAL_HPP_
38 #define FIX8_TICKVAL_HPP_
47 #pragma warning(disable: 4307) // chrono(132): warning C4307: '*': integral constant overflow in vc140
60 #if defined(__APPLE__) || defined(_MSC_VER)
61 using f8_clock = std::chrono::system_clock;
63 using f8_clock = std::chrono::high_resolution_clock;
66 using ticks = decltype(f8_time_point::min().time_since_epoch().count());
71 static const auto g_ticks(std::chrono::duration_cast<std::chrono::nanoseconds>
72 (f8_time_point::max().time_since_epoch()).count());
123 _value =
f8_time_point(std::chrono::duration_cast<f8_duration>(std::chrono::nanoseconds(that)));
129 ticks get_ticks()
const {
return std::chrono::duration_cast<std::chrono::nanoseconds>(_value.time_since_epoch()).count(); }
135 _value = f8_clock::now();
141 time_t
secs()
const {
return std::chrono::duration_cast<std::chrono::seconds>(_value.time_since_epoch()).count(); }
147 return std::chrono::duration_cast<std::chrono::milliseconds>(_value.time_since_epoch()).count() % std::milli::den;
154 return std::chrono::duration_cast<std::chrono::microseconds>(_value.time_since_epoch()).count() % std::micro::den;
161 return std::chrono::duration_cast<std::chrono::nanoseconds>(_value.time_since_epoch()).count() % std::nano::den;
168 return static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(_value.time_since_epoch()).count()) / std::nano::den;
181 return !b.
is_errorval() ? a <= *
this && *
this <= b : a <= *
this;
200 struct tm *
as_tm(
struct tm& result)
const
202 const time_t insecs(std::chrono::system_clock::to_time_t(_value));
204 gmtime_s(&result, &insecs);
206 gmtime_r(&insecs, &result);
216 return *
as_tm(result);
226 bool operator!()
const {
return _value.time_since_epoch() == std::chrono::nanoseconds::zero(); }
230 operator void*() {
return _value.time_since_epoch() == std::chrono::nanoseconds::zero() ?
nullptr :
this; }
316 oldtime.
_value += std::chrono::duration_cast<
f8_duration>(std::chrono::nanoseconds(ns));
326 oldtime.
_value -= std::chrono::duration_cast<
f8_duration>(std::chrono::nanoseconds(ns));
357 #endif // FIX8PRO_TICKVAL_HPP_
Tickval(time_t secs, long nsecs)
Tickval(const Tickval &from)
static const ticks million
static Tickval get_tickval()
friend bool operator==(const Tickval &a, const Tickval &b)
static const ticks & errorticks()
Tickval & operator=(ticks that)
friend Tickval operator-(const Tickval &newtime, const Tickval &oldtime)
void set(time_t secs, long nsecs)
f8_time_point::duration f8_duration
friend Tickval operator+(const Tickval &newtime, const Tickval &oldtime)
std::chrono::time_point< f8_clock > f8_time_point
static const ticks second
friend bool operator>(const Tickval &a, const Tickval &b)
friend std::ostream & operator>>(std::ostream &os, const Tickval &what)
std::chrono::high_resolution_clock f8_clock
struct tm * as_tm(struct tm &result) const
static const ticks billion
friend Tickval & operator-=(Tickval &oldtime, const Tickval &newtime)
static const ticks noticks
F8API const std::string & GetTimeAsStringMS(std::string &result, const class Tickval *tv=0, const unsigned dplaces=6, bool use_gm=false)
decltype(f8_time_point::min().time_since_epoch().count()) ticks
friend bool operator<(const Tickval &a, const Tickval &b)
static Tickval & get_tickval(Tickval &to)
friend bool operator!=(const Tickval &a, const Tickval &b)
friend Tickval & operator+=(Tickval &oldtime, const Tickval &newtime)
static const ticks minute
Tickval(f8_time_point from)
Tickval & operator=(const Tickval &that)
friend bool operator>=(const Tickval &a, const Tickval &b)
bool in_range(const Tickval &a, const Tickval &b) const
friend std::ostream & operator<<(std::ostream &os, const Tickval &what)
friend Tickval & operator+=(Tickval &oldtime, ticks ns)
Tickval & adjust(ticks by)
static const ticks thousand
Tickval(bool settonow=false)
friend Tickval & operator-=(Tickval &oldtime, ticks ns)
friend bool operator<=(const Tickval &a, const Tickval &b)