]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/time.cc
2 * Copyright (C) 1996-2014 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;
40 TimeEngine::~TimeEngine()
50 Time::FormatStrf(time_t t
)
54 static time_t last_t
= 0;
58 strftime(buf
, 127, "%Y/%m/%d %H:%M:%S", tm
);
66 Time::FormatHttpd(time_t t
)
69 static time_t last_t
= 0;
72 struct tm
*gmt
= gmtime(&t
);
75 int gmt_min
, gmt_hour
, gmt_yday
, day_offset
;
80 /* localtime & gmtime may use the same static data */
81 gmt_min
= gmt
->tm_min
;
82 gmt_hour
= gmt
->tm_hour
;
83 gmt_yday
= gmt
->tm_yday
;
87 day_offset
= lt
->tm_yday
- gmt_yday
;
88 /* wrap round on end of year */
91 else if (day_offset
< -1)
94 min_offset
= day_offset
* 1440 + (lt
->tm_hour
- gmt_hour
) * 60
95 + (lt
->tm_min
- gmt_min
);
97 len
= strftime(buf
, 127 - 5, "%d/%b/%Y:%H:%M:%S ", lt
);
98 snprintf(buf
+ len
, 128 - len
, "%+03d%02d",
99 (min_offset
/ 60) % 24,
103 strftime(buf
, 127, "%d/%b/%Y:%H:%M:%S -000", gmt
);