9#if __has_include("defs.h")
20timeval
operator+ (
const timeval& t1,
const timeval& t2);
21timeval
operator- (
const timeval& t1,
const timeval& t2);
22timeval&
operator+= (timeval& lhs,
const timeval& rhs);
23timeval&
operator-= (timeval& lhs,
const timeval& rhs);
24timeval
operator* (
const timeval& op1,
int op2);
25timeval
operator* (
int op1,
const timeval& op2);
26timeval
operator/ (
const timeval& op1,
int op2);
29inline bool operator== (
const timeval& t1,
const timeval& t2)
31 if (t1.tv_sec == t2.tv_sec)
32 return (t1.tv_usec == t2.tv_usec);
37#if __cplusplus < 202002L
41inline bool operator< (
const timeval& t1,
const timeval& t2)
43 if (t1.tv_sec != t2.tv_sec)
44 return (t1.tv_sec < t2.tv_sec);
46 return (t1.tv_usec < t2.tv_usec);
50inline bool operator> (
const timeval& t1,
const timeval& t2)
52 if (t1.tv_sec != t2.tv_sec)
53 return (t1.tv_sec > t2.tv_sec);
55 return (t1.tv_usec > t2.tv_usec);
59inline bool operator>= (
const timeval& t1,
const timeval& t2)
65inline bool operator<= (
const timeval& t1,
const timeval& t2)
71inline bool operator!= (
const timeval& t1,
const timeval& t2)
79inline auto operator<=> (
const timeval& t1,
const timeval& t2)
81 if (t1.tv_sec == t2.tv_sec)
82 return (t1.tv_usec <=> t2.tv_usec);
84 return (t1.tv_sec <=> t2.tv_sec);
95double secd (
const timeval& tv);
98void tosystime (
const timeval& tv, SYSTEMTIME* st);
99void tolocaltime (
const timeval& tv, SYSTEMTIME* st);
109inline timeval
operator+ (
const timeval& t1,
const timeval& t2)
112 ans.tv_usec = t1.tv_usec + t2.tv_usec;
113 ans.tv_sec = t1.tv_sec + t2.tv_sec;
119inline timeval
operator- (
const timeval& t1,
const timeval& t2)
123 ans.tv_usec = t1.tv_usec - t2.tv_usec;
124 ans.tv_sec = t1.tv_sec - t2.tv_sec;
132 lhs.tv_usec += rhs.tv_usec;
133 lhs.tv_sec += rhs.tv_sec;
141 lhs.tv_usec -= rhs.tv_usec;
142 lhs.tv_sec -= rhs.tv_sec;
148inline double secd (
const timeval& tv)
150 return tv.tv_sec + (double)tv.tv_usec / 1000000;
154inline LONGLONG
usec64 (
const timeval& tv)
156 return (LONGLONG)tv.tv_sec * 1000000L + (LONGLONG)tv.tv_usec;
163 tv.tv_sec = (int)(us / 1000000L);
164 tv.tv_usec = (int)(us % 1000000L);
173 tv.tv_usec = (long)((d - tv.tv_sec) * 1000000);
182 tv.tv_usec = op1.tv_usec * op2;
183 tv.tv_sec = op1.tv_sec * op2;
198 tv.tv_usec = op1.tv_usec / op2;
199 tv.tv_sec = op1.tv_sec / op2;
204inline ::std::ostream& operator<< (::std::ostream& os,
const timeval& tv)
206 os <<
"{ tv_sec: " << tv.tv_sec <<
", tv_usec: " << tv.tv_usec <<
'}';
bool operator<=(const timeval &t1, const timeval &t2)
"Less or equal than" operator
Definition tvops.h:65
bool operator!=(const timeval &t1, const timeval &t2)
"Not equal" operator
Definition tvops.h:71
void tosystime(const timeval &tv, SYSTEMTIME *st)
Convert from timeval format to SYSTEMTIME format.
Definition tvops.cpp:33
void tolocaltime(const timeval &tv, SYSTEMTIME *st)
Convert to local time (in a SYSTEMTIME structure)
Definition tvops.cpp:61
timeval operator/(const timeval &op1, int op2)
Division by an integer.
Definition tvops.h:195
timeval operator-(const timeval &t1, const timeval &t2)
Subtraction operator.
Definition tvops.h:119
timeval operator+(const timeval &t1, const timeval &t2)
Addition operator.
Definition tvops.h:109
timeval fromusec(LONGLONG us)
Conversion from 64-bit microseconds.
Definition tvops.h:160
bool operator>(const timeval &t1, const timeval &t2)
"Greater than" operator
Definition tvops.h:50
void normalize(timeval &tv)
Following an arithmetic operation, brings timeval structure to a canonical form where tv_usec is less...
Definition tvops.cpp:74
timeval zone_bias()
Return time zone bias.
Definition tvops.cpp:42
timeval operator*(const timeval &op1, int op2)
Multiplication by an integer.
Definition tvops.h:178
LONGLONG usec64(const timeval &tv)
Conversion to 64-bit microseconds.
Definition tvops.h:154
timeval fromsystime(const SYSTEMTIME &st)
Convert from UTC system time to Unix time scale (UTC form 01/01/70)
Definition tvops.cpp:20
timeval fromdouble(double d)
Conversion from floating-point seconds.
Definition tvops.h:169
double secd(const timeval &tv)
Conversion to floating-point seconds.
Definition tvops.h:148
timeval & operator-=(timeval &lhs, const timeval &rhs)
Subtraction assignment.
Definition tvops.h:139
bool operator>=(const timeval &t1, const timeval &t2)
"Greater or equal than" operator
Definition tvops.h:59
bool operator==(const timeval &t1, const timeval &t2)
Equality operator.
Definition tvops.h:29
bool operator<(const timeval &t1, const timeval &t2)
"Less than" operator
Definition tvops.h:41
timeval & operator+=(timeval &lhs, const timeval &rhs)
Addition assignment operator.
Definition tvops.h:130