diff --git a/include/timespec.h b/include/timespec.h index a65a9f1..3977477 100644 --- a/include/timespec.h +++ b/include/timespec.h @@ -44,3 +44,4 @@ struct mgos_timespec *timespec_create(); bool timespec_destroy(struct mgos_timespec **ts); bool timespec_add_spec(struct mgos_timespec *ts, const char *spec); bool timespec_match(const struct mgos_timespec *ts, const struct tm *tm); +bool timespec_match_now(const struct mgos_timespec *ts); diff --git a/src/timespec.c b/src/timespec.c index 9401b65..b3dc196 100644 --- a/src/timespec.c +++ b/src/timespec.c @@ -188,6 +188,21 @@ bool timespec_match(const struct mgos_timespec *ts, const struct tm *tm) { } // LOG(LL_DEBUG, ("start=%d stop=%d target=%d did not match", start, stop, target)); } - (void)tm; return false; } + +// Uses current time to match the timespec +bool timespec_match_now(const struct mgos_timespec *ts) { + time_t now; + struct tm *tm; + + if (!ts) { + return false; + } + now = time(NULL); + tm = localtime(&now); + if (!tm) { + return false; + } + return timespec_match(ts, tm); +}