From 39e24d70500359a12e263363a47af4bd426bab4b Mon Sep 17 00:00:00 2001 From: Tim McNamara Date: Thu, 4 Nov 2021 21:56:42 +1300 Subject: [PATCH] Fix offset calculation (fixes #51) --- ch9/ch9-clock3/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ch9/ch9-clock3/src/main.rs b/ch9/ch9-clock3/src/main.rs index a5c49632..b3c644c9 100644 --- a/ch9/ch9-clock3/src/main.rs +++ b/ch9/ch9-clock3/src/main.rs @@ -39,8 +39,8 @@ struct NTPResult { impl NTPResult { fn offset(&self) -> i64 { - let duration = (self.t2 - self.t1) + (self.t4 - self.t3); - duration.num_milliseconds() / 2 + let delta = self.delay(); + delta.abs() / 2 } fn delay(&self) -> i64 {