/*
- * 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.
#include "rfc1123.h"
#include <ctime>
+#include <iosfwd>
/* NP: sys/time.h is provided by libcompat */
/* Use uint64_t to store milliseconds */
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);
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
{