comparison src/http/ngx_http_parse_time.c @ 3208:8cec9724fe71

ngx_http_parse_time() should support full 32-bit time
author Igor Sysoev <igor@sysoev.ru>
date Thu, 15 Oct 2009 13:19:34 +0000
parents 154b5f8565a9
children d620f497c50f
comparison
equal deleted inserted replaced
3207:154b5f8565a9 3208:8cec9724fe71
14 ngx_http_parse_time(u_char *value, size_t len) 14 ngx_http_parse_time(u_char *value, size_t len)
15 { 15 {
16 u_char *p, *end; 16 u_char *p, *end;
17 ngx_int_t month; 17 ngx_int_t month;
18 ngx_uint_t day, year, hour, min, sec; 18 ngx_uint_t day, year, hour, min, sec;
19 uint64_t time;
19 enum { 20 enum {
20 no = 0, 21 no = 0,
21 rfc822, /* Tue, 10 Nov 2002 23:50:13 */ 22 rfc822, /* Tue, 10 Nov 2002 23:50:13 */
22 rfc850, /* Tuesday, 10-Dec-02 23:50:13 */ 23 rfc850, /* Tuesday, 10-Dec-02 23:50:13 */
23 isoc /* Tue Dec 10 23:50:13 2002 */ 24 isoc /* Tue Dec 10 23:50:13 2002 */
228 229
229 } else if (day > mday[month]) { 230 } else if (day > mday[month]) {
230 return NGX_ERROR; 231 return NGX_ERROR;
231 } 232 }
232 233
233 #if (NGX_TIME_T_SIZE <= 4)
234
235 if (year >= 2038) {
236 return NGX_ERROR;
237 }
238
239 #endif
240
241 /* 234 /*
242 * shift new year to March 1 and start months from 1 (not 0), 235 * shift new year to March 1 and start months from 1 (not 0),
243 * it is needed for Gauss' formula 236 * it is needed for Gauss' formula
244 */ 237 */
245 238
248 year -= 1; 241 year -= 1;
249 } 242 }
250 243
251 /* Gauss' formula for Grigorian days since March 1, 1 BC */ 244 /* Gauss' formula for Grigorian days since March 1, 1 BC */
252 245
253 return ( 246 time = (uint64_t) (
254 /* days in years including leap years since March 1, 1 BC */ 247 /* days in years including leap years since March 1, 1 BC */
255 248
256 365 * year + year / 4 - year / 100 + year / 400 249 365 * year + year / 4 - year / 100 + year / 400
257 250
258 /* days before the month */ 251 /* days before the month */
267 * 719527 days were between March 1, 1 BC and March 1, 1970, 260 * 719527 days were between March 1, 1 BC and March 1, 1970,
268 * 31 and 28 days were in January and February 1970 261 * 31 and 28 days were in January and February 1970
269 */ 262 */
270 263
271 - 719527 + 31 + 28) * 86400 + hour * 3600 + min * 60 + sec; 264 - 719527 + 31 + 28) * 86400 + hour * 3600 + min * 60 + sec;
265
266 #if (NGX_TIME_T_SIZE <= 4)
267
268 if (time > 0x7fffffff) {
269 return NGX_ERROR;
270 }
271
272 #endif
273
274 return (time_t) time;
272 } 275 }