1919
2020#include "build.h"
2121#include "cron.h"
22+ #include "tvheadend.h"
2223
2324#include <time.h>
2425#include <stdio.h>
@@ -323,6 +324,16 @@ cron_next ( cron_t *c, const time_t now, time_t *ret )
323324 mktime (& tmp );
324325 nxt .tm_isdst = tmp .tm_isdst ;
325326 * ret = mktime (& nxt );
327+ if (* ret <= now )
328+ * ret = mktime (& tmp );
329+ if (* ret <= now ) {
330+ #ifndef CRON_TEST
331+ tvherror ("cron" , "invalid time, now %" PRItime_t ", result %" PRItime_t , now , * ret );
332+ #else
333+ printf ("ERROR: invalid time, now %" PRItime_t ", result %" PRItime_t "\n" , now , * ret );
334+ #endif
335+ * ret = now + 600 ;
336+ }
326337 return 0 ;
327338}
328339
@@ -350,7 +361,7 @@ cron_multi_next ( cron_multi_t *cm, const time_t now, time_t *ret )
350361/*
351362 * Testing
352363 */
353- #if 0
364+ #ifdef CRON_TEST
354365static
355366void print_bits ( uint64_t b , int n )
356367{
@@ -369,7 +380,14 @@ main ( int argc, char **argv )
369380 struct tm tm ;
370381 char buf [128 ];
371382
372- time (& n );
383+ if (argc < 2 ) {
384+ printf ("Specify: CRON [NOW]\n" );
385+ return 1 ;
386+ }
387+ if (argc > 2 )
388+ n = atol (argv [2 ]);
389+ else
390+ time (& n );
373391 if (cron_set (& c , argv [1 ]))
374392 printf ("INVALID CRON: %s\n" , argv [1 ]);
375393 else {
@@ -381,15 +399,15 @@ main ( int argc, char **argv )
381399
382400 localtime_r (& n , & tm );
383401 strftime (buf , sizeof (buf ), "%Y-%m-%d %H:%M" , & tm );
384- printf ("NOW: %s \n" , buf );
402+ printf ("NOW: %ld - %s (DST %d) (ZONE %s) \n" , ( long ) n , buf , tm . tm_isdst , tm . tm_zone );
385403
386404 if (cron_next (& c , n , & n )) {
387405 printf ("FAILED to find NEXT\n" );
388406 return 1 ;
389407 }
390408 localtime_r (& n , & tm );
391409 strftime (buf , sizeof (buf ), "%Y-%m-%d %H:%M" , & tm );
392- printf ("NXT: %s \n" , buf );
410+ printf ("NXT: %ld - %s (DST %d) (ZONE %s) \n" , ( long ) n , buf , tm . tm_isdst , tm . tm_zone );
393411
394412 }
395413 return 0 ;
0 commit comments