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