Mercurial > hg > nginx-quic
comparison src/core/ngx_times.c @ 290:87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 16 Mar 2004 07:10:12 +0000 |
parents | e16dfb9b9afa |
children | ee394e997c77 |
comparison
equal
deleted
inserted
replaced
289:0750faf8d7e3 | 290:87e73f067470 |
---|---|
13 ngx_epoch_msec_t ngx_old_elapsed_msec; | 13 ngx_epoch_msec_t ngx_old_elapsed_msec; |
14 ngx_epoch_msec_t ngx_start_msec; | 14 ngx_epoch_msec_t ngx_start_msec; |
15 | 15 |
16 ngx_tm_t ngx_cached_gmtime; | 16 ngx_tm_t ngx_cached_gmtime; |
17 | 17 |
18 static char cached_err_log_time[] = "1970/09/28 12:00:00"; | 18 static u_char cached_err_log_time[] = "1970/09/28 12:00:00"; |
19 ngx_str_t ngx_cached_err_log_time; | 19 ngx_str_t ngx_cached_err_log_time; |
20 | 20 |
21 static char cached_http_time[] = "Mon, 28 Sep 1970 06:00:00 GMT"; | 21 static u_char cached_http_time[] = "Mon, 28 Sep 1970 06:00:00 GMT"; |
22 ngx_str_t ngx_cached_http_time; | 22 ngx_str_t ngx_cached_http_time; |
23 | 23 |
24 static char cached_http_log_time[] = "28/Sep/1970:12:00:00"; | 24 static u_char cached_http_log_time[] = "28/Sep/1970:12:00:00"; |
25 ngx_str_t ngx_cached_http_log_time; | 25 ngx_str_t ngx_cached_http_log_time; |
26 | 26 |
27 | 27 |
28 static char *week[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fir", "Sat" }; | 28 static char *week[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fir", "Sat" }; |
29 static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", | 29 static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
84 | 84 |
85 ngx_cached_time = s; | 85 ngx_cached_time = s; |
86 | 86 |
87 ngx_gmtime(ngx_cached_time, &ngx_cached_gmtime); | 87 ngx_gmtime(ngx_cached_time, &ngx_cached_gmtime); |
88 | 88 |
89 ngx_cached_http_time.len = ngx_snprintf(ngx_cached_http_time.data, | 89 ngx_cached_http_time.len = ngx_snprintf((char *) ngx_cached_http_time.data, |
90 sizeof("Mon, 28 Sep 1970 06:00:00 GMT"), | 90 sizeof("Mon, 28 Sep 1970 06:00:00 GMT"), |
91 "%s, %02d %s %4d %02d:%02d:%02d GMT", | 91 "%s, %02d %s %4d %02d:%02d:%02d GMT", |
92 week[ngx_cached_gmtime.ngx_tm_wday], | 92 week[ngx_cached_gmtime.ngx_tm_wday], |
93 ngx_cached_gmtime.ngx_tm_mday, | 93 ngx_cached_gmtime.ngx_tm_mday, |
94 months[ngx_cached_gmtime.ngx_tm_mon - 1], | 94 months[ngx_cached_gmtime.ngx_tm_mon - 1], |
97 ngx_cached_gmtime.ngx_tm_min, | 97 ngx_cached_gmtime.ngx_tm_min, |
98 ngx_cached_gmtime.ngx_tm_sec); | 98 ngx_cached_gmtime.ngx_tm_sec); |
99 | 99 |
100 ngx_localtime(&tm); | 100 ngx_localtime(&tm); |
101 | 101 |
102 ngx_cached_err_log_time.len = ngx_snprintf(ngx_cached_err_log_time.data, | 102 ngx_cached_err_log_time.len = ngx_snprintf((char *) |
103 ngx_cached_err_log_time.data, | |
103 sizeof("1970/09/28 12:00:00"), | 104 sizeof("1970/09/28 12:00:00"), |
104 "%4d/%02d/%02d %02d:%02d:%02d", | 105 "%4d/%02d/%02d %02d:%02d:%02d", |
105 tm.ngx_tm_year, tm.ngx_tm_mon, | 106 tm.ngx_tm_year, tm.ngx_tm_mon, |
106 tm.ngx_tm_mday, tm.ngx_tm_hour, | 107 tm.ngx_tm_mday, tm.ngx_tm_hour, |
107 tm.ngx_tm_min, tm.ngx_tm_sec); | 108 tm.ngx_tm_min, tm.ngx_tm_sec); |
108 | 109 |
109 ngx_cached_http_log_time.len = ngx_snprintf(ngx_cached_http_log_time.data, | 110 ngx_cached_http_log_time.len = ngx_snprintf((char *) |
111 ngx_cached_http_log_time.data, | |
110 sizeof("28/Sep/1970:12:00:00"), | 112 sizeof("28/Sep/1970:12:00:00"), |
111 "%02d/%s/%d:%02d:%02d:%02d", | 113 "%02d/%s/%d:%02d:%02d:%02d", |
112 tm.ngx_tm_mday, | 114 tm.ngx_tm_mday, |
113 months[tm.ngx_tm_mon - 1], | 115 months[tm.ngx_tm_mon - 1], |
114 tm.ngx_tm_year, | 116 tm.ngx_tm_year, |
121 #endif | 123 #endif |
122 | 124 |
123 } | 125 } |
124 | 126 |
125 | 127 |
126 size_t ngx_http_time(char *buf, time_t t) | 128 size_t ngx_http_time(u_char *buf, time_t t) |
127 { | 129 { |
128 ngx_tm_t tm; | 130 ngx_tm_t tm; |
129 | 131 |
130 ngx_gmtime(t, &tm); | 132 ngx_gmtime(t, &tm); |
131 | 133 |
132 return ngx_snprintf(buf, sizeof("Mon, 28 Sep 1970 06:00:00 GMT"), | 134 return ngx_snprintf((char *) buf, sizeof("Mon, 28 Sep 1970 06:00:00 GMT"), |
133 "%s, %02d %s %4d %02d:%02d:%02d GMT", | 135 "%s, %02d %s %4d %02d:%02d:%02d GMT", |
134 week[tm.ngx_tm_wday], | 136 week[tm.ngx_tm_wday], |
135 tm.ngx_tm_mday, | 137 tm.ngx_tm_mday, |
136 months[tm.ngx_tm_mon - 1], | 138 months[tm.ngx_tm_mon - 1], |
137 tm.ngx_tm_year, | 139 tm.ngx_tm_year, |
141 } | 143 } |
142 | 144 |
143 | 145 |
144 void ngx_gmtime(time_t t, ngx_tm_t *tp) | 146 void ngx_gmtime(time_t t, ngx_tm_t *tp) |
145 { | 147 { |
146 int sec, min, hour, mday, mon, year, wday, yday, days; | 148 ngx_int_t sec, min, hour, mday, mon, year, wday, yday, days; |
147 | 149 |
148 days = t / 86400; | 150 days = t / 86400; |
149 | 151 |
150 /* Jaunary 1, 1970 was Thursday */ | 152 /* Jaunary 1, 1970 was Thursday */ |
151 wday = (4 + days) % 7; | 153 wday = (4 + days) % 7; |
198 if ((year % 4 == 0) && (year % 100 || (year % 400 == 0))) { | 200 if ((year % 4 == 0) && (year % 100 || (year % 400 == 0))) { |
199 yday++; | 201 yday++; |
200 } | 202 } |
201 } | 203 } |
202 | 204 |
203 tp->ngx_tm_sec = sec; | 205 tp->ngx_tm_sec = (ngx_tm_sec_t) sec; |
204 tp->ngx_tm_min = min; | 206 tp->ngx_tm_min = (ngx_tm_min_t) min; |
205 tp->ngx_tm_hour = hour; | 207 tp->ngx_tm_hour = (ngx_tm_hour_t) hour; |
206 tp->ngx_tm_mday = mday; | 208 tp->ngx_tm_mday = (ngx_tm_mday_t) mday; |
207 tp->ngx_tm_mon = mon; | 209 tp->ngx_tm_mon = (ngx_tm_mon_t) mon; |
208 tp->ngx_tm_year = year; | 210 tp->ngx_tm_year = (ngx_tm_year_t) year; |
209 tp->ngx_tm_wday = wday; | 211 tp->ngx_tm_wday = (ngx_tm_wday_t) wday; |
210 } | 212 } |