Add timespec_match_now() based on localtime()
This commit is contained in:
@ -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);
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user