]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/time.cc
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 21 Time Functions */
12 #include "SquidTime.h"
14 struct timeval current_time
;
16 time_t squid_curtime
= 0;
21 #if GETTIMEOFDAY_NO_TZP
22 gettimeofday(¤t_time
);
25 gettimeofday(¤t_time
, NULL
);
28 current_dtime
= (double) current_time
.tv_sec
+
29 (double) current_time
.tv_usec
/ 1000000.0;
30 return squid_curtime
= current_time
.tv_sec
;
34 tvSubMsec(struct timeval t1
, struct timeval t2
)
36 return (t2
.tv_sec
- t1
.tv_sec
) * 1000 +
37 (t2
.tv_usec
- t1
.tv_usec
) / 1000;
41 tvSub(struct timeval
&res
, struct timeval
const &t1
, struct timeval
const &t2
)
43 res
.tv_sec
= t2
.tv_sec
- t1
.tv_sec
;
44 if (t2
.tv_usec
>= t1
.tv_usec
)
45 res
.tv_usec
= t2
.tv_usec
- t1
.tv_usec
;
48 res
.tv_usec
= t2
.tv_usec
+ 1000000 - t1
.tv_usec
;
52 void tvAdd(struct timeval
&res
, struct timeval
const &t1
, struct timeval
const &t2
)
54 res
.tv_sec
= t1
.tv_sec
+ t2
.tv_sec
;
55 res
.tv_usec
= t1
.tv_usec
+ t2
.tv_usec
;
56 if (res
.tv_usec
>= 1000000) {
58 res
.tv_usec
-= 1000000;
62 void tvAssignAdd(struct timeval
&t
, struct timeval
const &add
)
64 t
.tv_sec
+= add
.tv_sec
;
65 t
.tv_usec
+= add
.tv_usec
;
66 if (t
.tv_usec
>= 1000000) {
72 TimeEngine::~TimeEngine()
82 Time::FormatStrf(time_t t
)
86 static time_t last_t
= 0;
90 strftime(buf
, 127, "%Y/%m/%d %H:%M:%S", tm
);
98 Time::FormatHttpd(time_t t
)
100 static char buf
[128];
101 static time_t last_t
= 0;
104 struct tm
*gmt
= gmtime(&t
);
107 int gmt_min
, gmt_hour
, gmt_yday
, day_offset
;
112 /* localtime & gmtime may use the same static data */
113 gmt_min
= gmt
->tm_min
;
114 gmt_hour
= gmt
->tm_hour
;
115 gmt_yday
= gmt
->tm_yday
;
119 day_offset
= lt
->tm_yday
- gmt_yday
;
120 /* wrap round on end of year */
123 else if (day_offset
< -1)
126 min_offset
= day_offset
* 1440 + (lt
->tm_hour
- gmt_hour
) * 60
127 + (lt
->tm_min
- gmt_min
);
129 len
= strftime(buf
, 127 - 5, "%d/%b/%Y:%H:%M:%S ", lt
);
130 snprintf(buf
+ len
, 128 - len
, "%+03d%02d",
131 (min_offset
/ 60) % 24,
135 strftime(buf
, 127, "%d/%b/%Y:%H:%M:%S -000", gmt
);