comparison src/core/ngx_times.c @ 372:6639b93e81b2 NGINX_0_6_30

nginx 0.6.30 *) Change: now if an "include" directive pattern does not match any file, then nginx does not issue an error. *) Feature: now the time in directives may be specified without spaces, for example, "1h50m". *) Bugfix: memory leaks if the "ssl_verify_client" directive was on. Thanks to Chavelle Vincent. *) Bugfix: the "sub_filter" directive might set text to change into output. *) Bugfix: the "error_page" directive did not take into account arguments in redirected URI. *) Bugfix: now nginx always opens files in binary mode under Cygwin. *) Bugfix: nginx could not be built on OpenBSD; bug appeared in 0.6.15.
author Igor Sysoev <http://sysoev.ru>
date Tue, 29 Apr 2008 00:00:00 +0400
parents a39aab45a53f
children 05981f639d21
comparison
equal deleted inserted replaced
371:b6a2a305fdad 372:6639b93e81b2
201 201
202 202
203 void 203 void
204 ngx_gmtime(time_t t, ngx_tm_t *tp) 204 ngx_gmtime(time_t t, ngx_tm_t *tp)
205 { 205 {
206 ngx_uint_t n, sec, min, hour, mday, mon, year, wday, yday, days; 206 ngx_int_t yday;
207 ngx_uint_t n, sec, min, hour, mday, mon, year, wday, days, leap;
207 208
208 /* the calculation is valid for positive time_t only */ 209 /* the calculation is valid for positive time_t only */
210
209 n = (ngx_uint_t) t; 211 n = (ngx_uint_t) t;
210 212
211 days = n / 86400; 213 days = n / 86400;
212 214
213 /* Jaunary 1, 1970 was Thursday */ 215 /* Jaunary 1, 1970 was Thursday */
216
214 wday = (4 + days) % 7; 217 wday = (4 + days) % 7;
215 218
216 n %= 86400; 219 n %= 86400;
217 hour = n / 3600; 220 hour = n / 3600;
218 n %= 3600; 221 n %= 3600;
219 min = n / 60; 222 min = n / 60;
220 sec = n % 60; 223 sec = n % 60;
221 224
222 /* the algorithm based on Gauss's formula */ 225 /*
223 226 * the algorithm based on Gauss' formula,
227 * see src/http/ngx_http_parse_time.c
228 */
229
230 /* days since March 1, 1 BC */
224 days = days - (31 + 28) + 719527; 231 days = days - (31 + 28) + 719527;
225 232
226 year = days * 400 / (365 * 400 + 100 - 4 + 1); 233 /*
234 * The "days" should be adjusted to 1 only, however, some March 1st's go
235 * to previous year, so we adjust them to 2. This causes also shift of the
236 * last Feburary days to next year, but we catch the case when "yday"
237 * becomes negative.
238 */
239
240 year = (days + 2) * 400 / (365 * 400 + 100 - 4 + 1);
241
227 yday = days - (365 * year + year / 4 - year / 100 + year / 400); 242 yday = days - (365 * year + year / 4 - year / 100 + year / 400);
228 243
229 mon = (yday + 31) * 12 / 367; 244 if (yday < 0) {
230 mday = yday - (mon * 367 / 12 - 31); 245 leap = (year % 4 == 0) && (year % 100 || (year % 400 == 0));
231 246 yday = 365 + leap + yday;
232 mon += 2; 247 year--;
248 }
249
250 /*
251 * The empirical formula that maps "yday" to month.
252 * There are at least 10 variants, some of them are:
253 * mon = (yday + 31) * 15 / 459
254 * mon = (yday + 31) * 17 / 520
255 * mon = (yday + 31) * 20 / 612
256 */
257
258 mon = (yday + 31) * 10 / 306;
259
260 /* the Gauss' formula that evaluates days before the month */
261
262 mday = yday - (367 * mon / 12 - 30) + 1;
233 263
234 if (yday >= 306) { 264 if (yday >= 306) {
265
266 year++;
267 mon -= 10;
235 268
236 /* 269 /*
237 * there is no "yday" in Win32 SYSTEMTIME 270 * there is no "yday" in Win32 SYSTEMTIME
238 * 271 *
239 * yday -= 306; 272 * yday -= 306;
240 */ 273 */
241 274
242 year++; 275 } else {
243 mon -= 12; 276
244 277 mon += 2;
245 if (mday == 0) { 278
246 /* Jaunary 31 */ 279 /*
247 mon = 1; 280 * there is no "yday" in Win32 SYSTEMTIME
248 mday = 31; 281 *
249 282 * yday += 31 + 28 + leap;
250 } else if (mon == 2) { 283 */
251
252 if ((year % 4 == 0) && (year % 100 || (year % 400 == 0))) {
253 if (mday > 29) {
254 mon = 3;
255 mday -= 29;
256 }
257
258 } else if (mday > 28) {
259 mon = 3;
260 mday -= 28;
261 }
262 }
263 /*
264 * there is no "yday" in Win32 SYSTEMTIME
265 *
266 * } else {
267 * yday += 31 + 28;
268 *
269 * if ((year % 4 == 0) && (year % 100 || (year % 400 == 0))) {
270 * yday++;
271 * }
272 */
273 } 284 }
274 285
275 tp->ngx_tm_sec = (ngx_tm_sec_t) sec; 286 tp->ngx_tm_sec = (ngx_tm_sec_t) sec;
276 tp->ngx_tm_min = (ngx_tm_min_t) min; 287 tp->ngx_tm_min = (ngx_tm_min_t) min;
277 tp->ngx_tm_hour = (ngx_tm_hour_t) hour; 288 tp->ngx_tm_hour = (ngx_tm_hour_t) hour;