From c442696f8313fbb511fa2f5693d44031d881fd9f Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 11 Apr 2021 16:44:49 -0500 Subject: [PATCH] Bugfix: nanoseconds should become seconds when a second is at least reached. When adding to nanoseconds would result in a value greater than or equal to a second, instead increment by 1 second. --- level_3/controller/c/private-common.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/level_3/controller/c/private-common.c b/level_3/controller/c/private-common.c index 873ffc8..ba39259 100644 --- a/level_3/controller/c/private-common.c +++ b/level_3/controller/c/private-common.c @@ -505,7 +505,14 @@ extern "C" { gettimeofday(&now, 0); time->tv_sec = now.tv_sec + seconds; - time->tv_nsec = now.tv_usec * 1000 + nanos; + time->tv_nsec = (now.tv_usec * 1000) + nanos; + + // If tv_nsec is 1 second or greater, then increment seconds. + if (time->tv_nsec >= 1000000000) { + ++(time->tv_sec); + + time->tv_nsec -= 1000000000; + } } #endif // _di_controller_time_ -- 1.8.3.1