gadgets.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef SQUID__SRC_TIME_GADGETS_H
10 #define SQUID__SRC_TIME_GADGETS_H
11 
12 #include <ctime>
13 #include <iosfwd>
14 
15 /* Use uint64_t to store milliseconds */
16 typedef uint64_t time_msec_t;
17 
19 extern double current_dtime;
20 
22 extern time_t squid_curtime;
23 
26 time_t getCurrentTime();
27 
28 namespace Time {
29 
31 time_t ParseIso3307(const char *);
32 
39 const char *FormatRfc1123(time_t);
40 
42 time_t ParseRfc1123(const char *);
43 
50 const char *FormatStrf(time_t);
51 
58 const char *FormatHttpd(time_t);
59 
60 } // namespace Time
61 
63 extern struct timeval current_time;
64 
68 int tvSubUsec(struct timeval A, struct timeval B);
69 
72 double tvSubDsec(struct timeval A, struct timeval B);
73 
77 int tvSubMsec(struct timeval A, struct timeval B);
78 
81 void tvSub(struct timeval &res, struct timeval const &t1, struct timeval const &t2);
82 
85 void tvAdd(struct timeval &res, struct timeval const &t1, struct timeval const &t2);
86 
89 void tvAssignAdd(struct timeval &t, struct timeval const &add);
90 
93 inline long int tvToMsec(struct timeval &t)
94 {
95  return t.tv_sec * 1000 + t.tv_usec / 1000;
96 }
97 
99 std::ostream &operator <<(std::ostream &, const timeval &);
100 
101 // TODO: Remove direct timercmp() calls in legacy code.
102 
103 inline bool
104 operator <(const timeval &a, const timeval &b)
105 {
106  return timercmp(&a, &b, <);
107 }
108 
109 inline bool
110 operator >(const timeval &a, const timeval &b)
111 {
112  return timercmp(&a, &b, >);
113 }
114 
115 inline bool
116 operator !=(const timeval &a, const timeval &b)
117 {
118  return timercmp(&a, &b, !=);
119 }
120 
121 // Operators for timeval below avoid timercmp() because Linux timeradd(3) manual
122 // page says that their timercmp() versions "do not work" on some platforms.
123 
124 inline bool
125 operator <=(const timeval &a, const timeval &b)
126 {
127  return !(a > b);
128 }
129 
130 inline bool
131 operator >=(const timeval &a, const timeval &b)
132 {
133  return !(a < b);
134 }
135 
136 inline bool
137 operator ==(const timeval &a, const timeval &b)
138 {
139  return !(a != b);
140 }
141 
142 #endif /* SQUID__SRC_TIME_GADGETS_H */
143 
static uint32 A
Definition: md4.c:43
static uint32 B
Definition: md4.c:43
Time and Date handling tools.
Definition: Engine.h:12
time_t ParseRfc1123(const char *)
Convert from RFC 1123 style time: "www, DD MMM YYYY hh:mm:ss ZZZ".
Definition: rfc1123.cc:159
const char * FormatStrf(time_t)
Definition: gadgets.cc:100
const char * FormatRfc1123(time_t)
Definition: rfc1123.cc:202
const char * FormatHttpd(time_t)
Definition: gadgets.cc:116
time_t ParseIso3307(const char *)
Convert from ISO 3307 style time: YYYYMMDDHHMMSS or YYYYMMDDHHMMSS.xxx.
Definition: iso3307.cc:22
#define timercmp(tvp, uvp, cmp)
Definition: snmp_api_util.h:76
std::ostream & operator<<(std::ostream &, const timeval &)
prints <seconds>.<microseconds>
Definition: stub_libtime.cc:28
void tvAdd(struct timeval &res, struct timeval const &t1, struct timeval const &t2)
Definition: gadgets.cc:69
time_t squid_curtime
the current UNIX time in seconds
Definition: stub_libtime.cc:20
time_t getCurrentTime()
Definition: gadgets.cc:22
bool operator>=(const timeval &a, const timeval &b)
Definition: gadgets.h:131
void tvSub(struct timeval &res, struct timeval const &t1, struct timeval const &t2)
Definition: gadgets.cc:58
uint64_t time_msec_t
Definition: gadgets.h:16
bool operator==(const timeval &a, const timeval &b)
Definition: gadgets.h:137
struct timeval current_time
the current UNIX time in timeval {seconds, microseconds} format
Definition: gadgets.cc:17
bool operator<(const timeval &a, const timeval &b)
Definition: gadgets.h:104
double current_dtime
the current UNIX time in seconds (with microsecond precision)
Definition: stub_libtime.cc:19
int tvSubUsec(struct timeval A, struct timeval B)
Definition: gadgets.cc:37
int tvSubMsec(struct timeval A, struct timeval B)
Definition: gadgets.cc:51
bool operator!=(const timeval &a, const timeval &b)
Definition: gadgets.h:116
bool operator<=(const timeval &a, const timeval &b)
Definition: gadgets.h:125
long int tvToMsec(struct timeval &t)
Definition: gadgets.h:93
bool operator>(const timeval &a, const timeval &b)
Definition: gadgets.h:110
void tvAssignAdd(struct timeval &t, struct timeval const &add)
Definition: gadgets.cc:79
double tvSubDsec(struct timeval A, struct timeval B)
Definition: gadgets.cc:44

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors