aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/libraries/LumbrJack.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-05-16 10:34:31 +1000
committerDavid Walter Seikel2014-05-16 10:34:31 +1000
commitb6489395e103929445d78f9a8145cf62262fd82e (patch)
tree4a87062ec2b9630f783406e101bc12c18392e244 /src/libraries/LumbrJack.c
parentImplement llCSV2List(). (diff)
downloadSledjHamr-b6489395e103929445d78f9a8145cf62262fd82e.zip
SledjHamr-b6489395e103929445d78f9a8145cf62262fd82e.tar.gz
SledjHamr-b6489395e103929445d78f9a8145cf62262fd82e.tar.bz2
SledjHamr-b6489395e103929445d78f9a8145cf62262fd82e.tar.xz
Move timeDiff() to LumbrJack, it has more than one user now.
Diffstat (limited to 'src/libraries/LumbrJack.c')
-rw-r--r--src/libraries/LumbrJack.c24
1 files changed, 24 insertions, 0 deletions
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)
86 strftime(date, DATE_TIME_LEN, "%d/%m/%Y %H:%M:%S\r", newTime); 86 strftime(date, DATE_TIME_LEN, "%d/%m/%Y %H:%M:%S\r", newTime);
87 return (dateTime); 87 return (dateTime);
88} 88}
89
90float timeDiff(struct timeval *now, struct timeval *then)
91{
92 if (0 == gettimeofday(now, 0))
93 {
94 struct timeval thisTime = { 0, 0 };
95 double result = 0.0;
96
97 thisTime.tv_sec = now->tv_sec;
98 thisTime.tv_usec = now->tv_usec;
99 if (thisTime.tv_usec < then->tv_usec)
100 {
101 thisTime.tv_sec--;
102 thisTime.tv_usec += 1000000;
103 }
104 thisTime.tv_usec -= then->tv_usec;
105 thisTime.tv_sec -= then->tv_sec;
106 result = ((double) thisTime.tv_usec) / ((double) 1000000.0);
107 result += thisTime.tv_sec;
108 return result;
109 }
110 else
111 return 0.0;
112}