Add timespec_match_now() based on localtime()

This commit is contained in:
Pim van Pelt
2018-11-04 15:43:32 +01:00
parent af9db0395d
commit d5778c6fba
2 changed files with 17 additions and 1 deletions

View File

@ -44,3 +44,4 @@ struct mgos_timespec *timespec_create();
bool timespec_destroy(struct mgos_timespec **ts); bool timespec_destroy(struct mgos_timespec **ts);
bool timespec_add_spec(struct mgos_timespec *ts, const char *spec); 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(const struct mgos_timespec *ts, const struct tm *tm);
bool timespec_match_now(const struct mgos_timespec *ts);

View File

@ -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)); // LOG(LL_DEBUG, ("start=%d stop=%d target=%d did not match", start, stop, target));
} }
(void)tm;
return false; 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);
}