]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
cron: fix the cron_next for DST change, fixes #3627 v4.0.9
authorJaroslav Kysela <perex@perex.cz>
Sun, 13 Mar 2016 16:42:56 +0000 (17:42 +0100)
committerJaroslav Kysela <perex@perex.cz>
Mon, 14 Mar 2016 09:10:57 +0000 (10:10 +0100)
src/cron.c

index 908f18af9658a4a08372bd9e2c9a3c71fc6cd3c1..c019fa7d22cb126aedc21d1d6081929b555c6488 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "build.h"
 #include "cron.h"
+#include "tvheadend.h"
 
 #include <time.h>
 #include <stdio.h>
@@ -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;
 }
 
@@ -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 )
 {
@@ -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 {
@@ -381,7 +399,7 @@ 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");
@@ -389,7 +407,7 @@ main ( int argc, char **argv )
     }
     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;