From d5778c6fbac26a5222f261387f24e100eb5232fb Mon Sep 17 00:00:00 2001
From: Pim van Pelt <pim@ipng.nl>
Date: Sun, 4 Nov 2018 15:43:32 +0100
Subject: [PATCH] Add timespec_match_now() based on localtime()

---
 include/timespec.h |  1 +
 src/timespec.c     | 17 ++++++++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

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);
+}