gpsd-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Incorrect time unit names


From: Mick Durkin
Subject: Incorrect time unit names
Date: Sat, 9 Oct 2021 20:46:59 +0100
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0

Hi,

While inspecting the code of the tests for timespecs and the corresponding
include file, I noticed one of the conversions was "reversed".

Specifically, there was a #define for the number of milliseconds in a
nanosecond, which is clearly named backwards although the use in the
code was correct.

Below are the 2 diffs I generated to correct this. Not important, but it
satisfies my OCD 8^).

BR

Mick
===========================================================

Change to timespec.h

$ git diff -u include/timespec.h
diff --git a/include/timespec.h b/include/timespec.h
index f608cb4b1..c0dc36cd2 100644
--- a/include/timespec.h
+++ b/include/timespec.h
@@ -10,13 +10,13 @@
 #include <stdbool.h>       /* for bool */

 #define NS_IN_SEC       1000000000LL     /* nanoseconds in a second */
-#define MS_IN_NS        1000000LL        /* milliseconds in a nano second */
+#define NS_IN_MS        1000000LL        /* nanoseconds in a millisecond */
 #define US_IN_SEC       1000000LL        /* microseconds in a second */
 #define MS_IN_SEC       1000LL           /* milliseconds in a second */

-/* convert a timespec_t to an int64_t of milli seconds */
+/* convert a timespec_t to an int64_t of milliseconds */
 #define TSTOMS(ts) ((int64_t)((ts)->tv_sec) * MS_IN_SEC + \
-                    (int64_t)((ts)->tv_nsec / MS_IN_NS))
+                    (int64_t)((ts)->tv_nsec / NS_IN_MS))

 /* normalize a timespec
  *

===========================================================

Change to test_timespec.c

$ git diff -u tests/test_timespec.c
diff --git a/tests/test_timespec.c b/tests/test_timespec.c
index d2199fa0c..a45b99a29 100644
--- a/tests/test_timespec.c
+++ b/tests/test_timespec.c
@@ -172,8 +172,8 @@ struct ts_to_ms_test ts_to_ms_tests[] = {
         { TS_N_ONEM,        -60000, 0},
         { TS_N_ONEH,        -3600000, 0},
         { TS_N_ONED,        -86400000, 0},
-        { { -1, MS_IN_NS},  -999, 0},
-        { { -1, -MS_IN_NS}, -1001, 0},
+        { { -1, NS_IN_MS},  -999, 0},
+        { { -1, -NS_IN_MS}, -1001, 0},
         // Note no (extra) loss of precision on the following
         { TS_2037,          2145916799000ULL, 0},
         { TS_2037_ONE,      2145916799000ULL, 0},



reply via email to

[Prev in Thread] Current Thread [Next in Thread]