summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Van Doorn <vandoorn.nick@gmail.com>2018-01-26 13:47:53 -0800
committerNick Van Doorn <vandoorn.nick@gmail.com>2018-01-26 13:47:53 -0800
commit9ae96091978fe5f2fcd64a9b7103ba61b9ed6f18 (patch)
tree4fdd4a2a5b9053e447c9eae34281aeab1bdad6ad
parent49d6a7a827baa6ff7250371021693c5b6e7b987b (diff)
Add some time helpers
-rw-r--r--util.c19
-rw-r--r--util.h2
2 files changed, 21 insertions, 0 deletions
diff --git a/util.c b/util.c
index 66e717c..6d79f5d 100644
--- a/util.c
+++ b/util.c
@@ -119,6 +119,25 @@ le_result_t util_flattenRes (le_result_t *res, int nRes) {
return LE_OK;
}
+int util_getUnixDatetime () {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return tv.tv_sec;
+}
+
+/**
+ * Convenience function to get current time as uint64_t.
+ *
+ * @return
+ * Current time as a uint64_t
+ */
+uint64_t GetCurrentTimestamp(void) {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ uint64_t utcMilliSec = (uint64_t)(tv.tv_sec) * 1000 + (uint64_t)(tv.tv_usec) / 1000;
+ return utcMilliSec;
+}
+
// Functions below are deprecated
void delayMicro (unsigned long microsecs) {
unsigned long retTime = getTimeMicrosecs() + microsecs;
diff --git a/util.h b/util.h
index 93d0e12..a706588 100644
--- a/util.h
+++ b/util.h
@@ -33,7 +33,9 @@ le_result_t gpio_setHigh (int pin);
void delayMicro (unsigned long microsecs);
void delayMilli (unsigned long millisecs);
long getTimeMicrosecs ();
+uint64_t GetCurrentTimestamp (void);
+int util_getUnixDatetime ();
le_result_t util_flattenRes (le_result_t *res, int nRes);
#endif