From b6489395e103929445d78f9a8145cf62262fd82e Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Fri, 16 May 2014 10:34:31 +1000 Subject: Move timeDiff() to LumbrJack, it has more than one user now. --- src/libraries/LumbrJack.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/libraries/LumbrJack.c') diff --git a/src/libraries/LumbrJack.c b/src/libraries/LumbrJack.c index e873d02..8d08622 100644 --- a/src/libraries/LumbrJack.c +++ b/src/libraries/LumbrJack.c @@ -86,3 +86,27 @@ char *getDateTime(struct tm **nowOut, char *dateOut, time_t *timeOut) strftime(date, DATE_TIME_LEN, "%d/%m/%Y %H:%M:%S\r", newTime); return (dateTime); } + +float timeDiff(struct timeval *now, struct timeval *then) +{ + if (0 == gettimeofday(now, 0)) + { + struct timeval thisTime = { 0, 0 }; + double result = 0.0; + + thisTime.tv_sec = now->tv_sec; + thisTime.tv_usec = now->tv_usec; + if (thisTime.tv_usec < then->tv_usec) + { + thisTime.tv_sec--; + thisTime.tv_usec += 1000000; + } + thisTime.tv_usec -= then->tv_usec; + thisTime.tv_sec -= then->tv_sec; + result = ((double) thisTime.tv_usec) / ((double) 1000000.0); + result += thisTime.tv_sec; + return result; + } + else + return 0.0; +} -- cgit v1.1