From ec81b4c98b2568891eb0a4113efaadcd41abc792 Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Mon, 21 Apr 2014 14:46:31 +0100 Subject: [PATCH] util cron: fix possible DST issue really not sure this will work, needs testing --- src/cron.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cron.c b/src/cron.c index 0dbcbbfd..325ff6d1 100644 --- a/src/cron.c +++ b/src/cron.c @@ -181,11 +181,14 @@ days_in_month ( int year, int mon ) int cron_next ( cron_t *c, const time_t now, time_t *ret ) { - struct tm nxt; + struct tm nxt, tmp; int endyear; localtime_r(&now, &nxt); endyear = nxt.tm_year + 10; + /* Clear seconds */ + nxt.tm_sec = 0; + /* Invalid day */ if (!(c->c_mday & (0x1LL << (nxt.tm_mday-1))) || !(c->c_wday & (0x1LL << (nxt.tm_wday))) || @@ -267,8 +270,9 @@ cron_next ( cron_t *c, const time_t now, time_t *ret ) } /* Create time */ - // TODO: not sure this will provide the correct time with respect to DST! - nxt.tm_isdst = 0; + memcpy(&tmp, &nxt, sizeof(tmp)); + mktime(&tmp); + nxt.tm_isdst = tmp.tm_isdst; *ret = mktime(&nxt); return 0; }