From: Kevin Day Date: Sun, 11 Apr 2021 21:44:49 +0000 (-0500) Subject: Bugfix: nanoseconds should become seconds when a second is at least reached. X-Git-Tag: 0.5.3~59 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=c442696f8313fbb511fa2f5693d44031d881fd9f;p=fll 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. --- 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_