From 19b9cf2139213acecfe6c8f2079d101557c0c312 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Sat, 21 May 2016 00:19:00 -0400 Subject: [PATCH] lib/realtime: fix `Timespec::-` MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/realtime.nit | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/realtime.nit b/lib/realtime.nit index 523f63e..39c5a27 100644 --- a/lib/realtime.nit +++ b/lib/realtime.nit @@ -73,13 +73,16 @@ extern class Timespec `{struct timespec*`} clock_gettime(CLOCK_MONOTONIC, self); `} - # Substract a Timespec from `self`. - fun - ( o : Timespec ) : Timespec + # Subtract `other` from `self` + fun -(other: Timespec): Timespec do - var s = sec - o.sec - var ns = nanosec - o.nanosec - if ns > nanosec then s += 1 - return new Timespec( s, ns ) + var s = sec - other.sec + var ns = nanosec - other.nanosec + if ns < 0 then + s -= 1 + ns += 1000000000 + end + return new Timespec(s, ns) end # Number of whole seconds of elapsed time. -- 1.7.9.5