#include "build.h"
#include "cron.h"
+#include "tvheadend.h"
#include <time.h>
#include <stdio.h>
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;
}
/*
* Testing
*/
-#if 0
+#ifdef CRON_TEST
static
void print_bits ( uint64_t b, int n )
{
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 {
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");
}
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;