hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit bab9aefa2f6682aa4a850cde6f3f465a8cf21ef0
parent c2c41c1d2616baedbc419d53e75dcf29c4dae178
Author: Byron Torres <b@torresjrjr.com>
Date:   Tue, 14 Sep 2021 00:21:17 +0100

time: add time::diff

Signed-off-by: Byron Torres <b@torresjrjr.com>

Diffstat:
Mtime/arithm.ha | 14+++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/time/arithm.ha b/time/arithm.ha @@ -4,7 +4,15 @@ // Adds a [[duration]] to an [[instant]], returning an instant further in the // future (given a positive duration), or further in the past (given a negative // duration). -export fn add(a: instant, b: duration) instant = instant { - sec = a.sec + b / SECOND, - nsec = a.nsec + b, +export fn add(a: instant, d: duration) instant = instant { + sec = a.sec + d / SECOND, + nsec = a.nsec + d, +}; + +// Returns the duration from [[instant]] a to [[instant]] b. +// If a is earlier than b, the duration is positive. +// If a is equivilent to b, the duration is zero. +// If a is later than b, the duration is negative. +export fn diff(a: instant, b: instant) duration = { + return ((b.sec - a.sec) * SECOND) + (b.nsec - a.nsec); };