util cron: fix possible DST issue
really not sure this will work, needs testing
This commit is contained in:
parent
ae0c2f5334
commit
ec81b4c98b
1 changed files with 7 additions and 3 deletions
10
src/cron.c
10
src/cron.c
|
@ -181,11 +181,14 @@ days_in_month ( int year, int mon )
|
||||||
int
|
int
|
||||||
cron_next ( cron_t *c, const time_t now, time_t *ret )
|
cron_next ( cron_t *c, const time_t now, time_t *ret )
|
||||||
{
|
{
|
||||||
struct tm nxt;
|
struct tm nxt, tmp;
|
||||||
int endyear;
|
int endyear;
|
||||||
localtime_r(&now, &nxt);
|
localtime_r(&now, &nxt);
|
||||||
endyear = nxt.tm_year + 10;
|
endyear = nxt.tm_year + 10;
|
||||||
|
|
||||||
|
/* Clear seconds */
|
||||||
|
nxt.tm_sec = 0;
|
||||||
|
|
||||||
/* Invalid day */
|
/* Invalid day */
|
||||||
if (!(c->c_mday & (0x1LL << (nxt.tm_mday-1))) ||
|
if (!(c->c_mday & (0x1LL << (nxt.tm_mday-1))) ||
|
||||||
!(c->c_wday & (0x1LL << (nxt.tm_wday))) ||
|
!(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 */
|
/* Create time */
|
||||||
// TODO: not sure this will provide the correct time with respect to DST!
|
memcpy(&tmp, &nxt, sizeof(tmp));
|
||||||
nxt.tm_isdst = 0;
|
mktime(&tmp);
|
||||||
|
nxt.tm_isdst = tmp.tm_isdst;
|
||||||
*ret = mktime(&nxt);
|
*ret = mktime(&nxt);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue