]> git.ipfire.org Git - thirdparty/squid.git/blob - src/SquidTime.h
Simplified MSNT basic auth helper
[thirdparty/squid.git] / src / SquidTime.h
1 /*
2 * Copyright (C) 1996-2014 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 /* DEBUG: section 21 Time Functions */
10
11 #ifndef SQUID_TIME_H
12 #define SQUID_TIME_H
13
14 #include "rfc1123.h"
15
16 #include <ctime>
17 /* NP: sys/time.h is provided by libcompat */
18
19 /* globals for accessing time */
20 extern struct timeval current_time;
21 extern double current_dtime;
22 extern time_t squid_curtime;
23
24 time_t getCurrentTime(void);
25 int tvSubMsec(struct timeval, struct timeval);
26
27 /// timeval substraction operation
28 /// \param[out] res = t2 - t1
29 void tvSub(struct timeval &res, struct timeval const &t1, struct timeval const &t2);
30
31 /// timeval addition operation
32 /// \param[out] res = t1 + t2
33 void tvAdd(struct timeval &res, struct timeval const &t1, struct timeval const &t2);
34
35 /// timeval addition assignment operation
36 /// \param[out] t += add
37 void tvAssignAdd(struct timeval &t, struct timeval const &add);
38
39 /// Convert timeval to milliseconds
40 inline long int tvToMsec(struct timeval &t)
41 {
42 return t.tv_sec * 1000 + t.tv_usec / 1000;
43 }
44
45 /** event class for doing synthetic time etc */
46 class TimeEngine
47 {
48
49 public:
50 virtual ~TimeEngine();
51
52 /** tick the clock - update from the OS or other time source, */
53 virtual void tick();
54 };
55
56 namespace Time
57 {
58
59 /** Display time as a formatted human-readable string.
60 * Time syntax is
61 * "YYYY/MM/DD hh:mm:ss"
62 *
63 * Output is only valid until next call to this function.
64 */
65 const char *FormatStrf(time_t t);
66
67 /** Display time as a formatted human-readable string.
68 * Time string syntax used is that of Apache httpd.
69 * "DD/MMM/YYYY:hh:mm:ss zzzz"
70 *
71 * Output is only valid until next call to this function.
72 */
73 const char *FormatHttpd(time_t t);
74
75 } // namespace Time
76
77 #endif /* SQUID_TIME_H */
78