comparison src/core/ngx_times.c @ 2162:429269167fab

ngx_next_time()
author Igor Sysoev <igor@sysoev.ru>
date Mon, 11 Aug 2008 15:28:15 +0000
parents 5bb2c374cab2
children bf38420c9e25
comparison
equal deleted inserted replaced
2161:904eab9dedb6 2162:429269167fab
289 tp->ngx_tm_mday = (ngx_tm_mday_t) mday; 289 tp->ngx_tm_mday = (ngx_tm_mday_t) mday;
290 tp->ngx_tm_mon = (ngx_tm_mon_t) mon; 290 tp->ngx_tm_mon = (ngx_tm_mon_t) mon;
291 tp->ngx_tm_year = (ngx_tm_year_t) year; 291 tp->ngx_tm_year = (ngx_tm_year_t) year;
292 tp->ngx_tm_wday = (ngx_tm_wday_t) wday; 292 tp->ngx_tm_wday = (ngx_tm_wday_t) wday;
293 } 293 }
294
295
296 time_t
297 ngx_next_time(time_t when)
298 {
299 time_t now, next;
300 struct tm tm;
301
302 now = ngx_time();
303
304 ngx_libc_localtime(now, &tm);
305
306 tm.tm_hour = (int) (when / 3600);
307 when %= 3600;
308 tm.tm_min = (int) (when / 60);
309 tm.tm_sec = (int) (when % 60);
310
311 next = mktime(&tm);
312
313 if (next == -1) {
314 return -1;
315 }
316
317 if (next - now > 0) {
318 return next;
319 }
320
321 tm.tm_mday++;
322
323 /* mktime() should normalize a date (Jan 32, etc) */
324
325 next = mktime(&tm);
326
327 if (next != -1) {
328 return next;
329 }
330
331 return -1;
332 }