# HG changeset patch # User Igor Sysoev # Date 1201792471 0 # Node ID 085e536d856d5990a03d4ed0c27528b065d576e2 # Parent 5d076348c121d35cc30431fe2f72fff5e6f21935 treat time_t as unsigned time diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c --- a/src/core/ngx_times.c +++ b/src/core/ngx_times.c @@ -203,18 +203,21 @@ ngx_http_cookie_time(u_char *buf, time_t void ngx_gmtime(time_t t, ngx_tm_t *tp) { - ngx_int_t sec, min, hour, mday, mon, year, wday, yday, days; + ngx_uint_t n, sec, min, hour, mday, mon, year, wday, yday, days; - days = (ngx_int_t) (t / 86400); + /* the calculation is valid for positive time_t only */ + n = (ngx_uint_t) t; + + days = n / 86400; /* Jaunary 1, 1970 was Thursday */ wday = (4 + days) % 7; - t %= 86400; - hour = (ngx_int_t) (t / 3600); - t %= 3600; - min = (ngx_int_t) (t / 60); - sec = (ngx_int_t) (t % 60); + n %= 86400; + hour = n / 3600; + n %= 3600; + min = n / 60; + sec = n % 60; /* the algorithm based on Gauss's formula */