gadgets.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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 */
16typedef uint64_t time_msec_t;
17
19extern double current_dtime;
20
22extern time_t squid_curtime;
23
26time_t getCurrentTime();
27
28namespace Time {
29
31time_t ParseIso3307(const char *);
32
39const char *FormatRfc1123(time_t);
40
42time_t ParseRfc1123(const char *);
43
50const char *FormatStrf(time_t);
51
58const char *FormatHttpd(time_t);
59
60} // namespace Time
61
63extern struct timeval current_time;
64
68int tvSubUsec(struct timeval A, struct timeval B);
69
72double tvSubDsec(struct timeval A, struct timeval B);
73
77int tvSubMsec(struct timeval A, struct timeval B);
78
81void tvSub(struct timeval &res, struct timeval const &t1, struct timeval const &t2);
82
85void tvAdd(struct timeval &res, struct timeval const &t1, struct timeval const &t2);
86
89void tvAssignAdd(struct timeval &t, struct timeval const &add);
90
93inline long int tvToMsec(struct timeval &t)
94{
95 return t.tv_sec * 1000 + t.tv_usec / 1000;
96}
97
99std::ostream &operator <<(std::ostream &, const timeval &);
100
101// TODO: Remove direct timercmp() calls in legacy code.
102
103inline bool
104operator <(const timeval &a, const timeval &b)
105{
106 return timercmp(&a, &b, <);
107}
108
109inline bool
110operator >(const timeval &a, const timeval &b)
111{
112 return timercmp(&a, &b, >);
113}
114
115inline bool
116operator !=(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
124inline bool
125operator <=(const timeval &a, const timeval &b)
126{
127 return !(a > b);
128}
129
130inline bool
131operator >=(const timeval &a, const timeval &b)
132{
133 return !(a < b);
134}
135
136inline bool
137operator ==(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:153
const char * FormatStrf(time_t)
Definition: gadgets.cc:100
const char * FormatRfc1123(time_t)
Definition: rfc1123.cc:196
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:18
#define timercmp(tvp, uvp, cmp)
Definition: snmp_api_util.h:76
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
std::ostream & operator<<(std::ostream &, const timeval &)
prints <seconds>.<microseconds>
Definition: stub_libtime.cc:28
double tvSubDsec(struct timeval A, struct timeval B)
Definition: gadgets.cc:44

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors