Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
cron: fix the cron_next for DST change, fixes #3627
  • Loading branch information
perexg committed Mar 13, 2016
1 parent 41b5def commit 3927788
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/cron.c
Expand Up @@ -19,6 +19,7 @@

#include "build.h"
#include "cron.h"
#include "tvheadend.h"

#include <time.h>
#include <stdio.h>
Expand Down Expand Up @@ -323,6 +324,16 @@ cron_next ( cron_t *c, const time_t now, time_t *ret )
mktime(&tmp);
nxt.tm_isdst = tmp.tm_isdst;
*ret = mktime(&nxt);
if (*ret <= now)
*ret = mktime(&tmp);
if (*ret <= now) {
#ifndef CRON_TEST
tvherror("cron", "invalid time, now %"PRItime_t", result %"PRItime_t, now, *ret);
#else
printf("ERROR: invalid time, now %"PRItime_t", result %"PRItime_t"\n", now, *ret);
#endif
*ret = now + 600;
}
return 0;
}

Expand Down Expand Up @@ -350,7 +361,7 @@ cron_multi_next ( cron_multi_t *cm, const time_t now, time_t *ret )
/*
* Testing
*/
#if 0
#ifdef CRON_TEST
static
void print_bits ( uint64_t b, int n )
{
Expand All @@ -369,7 +380,14 @@ main ( int argc, char **argv )
struct tm tm;
char buf[128];

time(&n);
if (argc < 2) {
printf("Specify: CRON [NOW]\n");
return 1;
}
if (argc > 2)
n = atol(argv[2]);
else
time(&n);
if (cron_set(&c, argv[1]))
printf("INVALID CRON: %s\n", argv[1]);
else {
Expand All @@ -381,15 +399,15 @@ main ( int argc, char **argv )

localtime_r(&n, &tm);
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", &tm);
printf("NOW: %s\n", buf);
printf("NOW: %ld - %s (DST %d) (ZONE %s)\n", (long)n, buf, tm.tm_isdst, tm.tm_zone);

if (cron_next(&c, n, &n)) {
printf("FAILED to find NEXT\n");
return 1;
}
localtime_r(&n, &tm);
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", &tm);
printf("NXT: %s\n", buf);
printf("NXT: %ld - %s (DST %d) (ZONE %s)\n", (long)n, buf, tm.tm_isdst, tm.tm_zone);

}
return 0;
Expand Down

0 comments on commit 3927788

Please sign in to comment.