]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/SquidTime.h
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / SquidTime.h
index bea368612df257d555a31cb194944a1f59f60afe..125eb9c676b2652f5b981b444afbc0bb2fb90185 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1996-2019 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
@@ -14,6 +14,7 @@
 #include "rfc1123.h"
 
 #include <ctime>
+#include <iosfwd>
 /* NP: sys/time.h is provided by libcompat */
 
 /* Use uint64_t to store milliseconds */
@@ -27,7 +28,7 @@ extern time_t squid_curtime;
 time_t getCurrentTime(void);
 int tvSubMsec(struct timeval, struct timeval);
 
-/// timeval substraction operation
+/// timeval subtraction operation
 /// \param[out] res = t2 - t1
 void tvSub(struct timeval &res, struct timeval const &t1, struct timeval const &t2);
 
@@ -56,6 +57,50 @@ public:
     virtual void tick();
 };
 
+// TODO: Remove direct timercmp() calls in legacy code.
+
+inline bool
+operator <(const timeval &a, const timeval &b)
+{
+    return timercmp(&a, &b, <);
+}
+
+inline bool
+operator >(const timeval &a, const timeval &b)
+{
+    return timercmp(&a, &b, >);
+}
+
+inline bool
+operator !=(const timeval &a, const timeval &b)
+{
+    return timercmp(&a, &b, !=);
+}
+
+// Operators for timeval below avoid timercmp() because Linux timeradd(3) manual
+// page says that their timercmp() versions "do not work" on some platforms.
+
+inline bool
+operator <=(const timeval &a, const timeval &b)
+{
+    return !(a > b);
+}
+
+inline bool
+operator >=(const timeval &a, const timeval &b)
+{
+    return !(a < b);
+}
+
+inline bool
+operator ==(const timeval &a, const timeval &b)
+{
+    return !(a != b);
+}
+
+/// prints <seconds>.<microseconds>
+std::ostream &operator <<(std::ostream &, const timeval &);
+
 namespace Time
 {