Skip to content

Commit 39e24d7

Browse files
authored
Fix offset calculation (fixes rust-in-action#51)
1 parent cff02d5 commit 39e24d7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ch9/ch9-clock3/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ struct NTPResult {
3939

4040
impl NTPResult {
4141
fn offset(&self) -> i64 {
42-
let duration = (self.t2 - self.t1) + (self.t4 - self.t3);
43-
duration.num_milliseconds() / 2
42+
let delta = self.delay();
43+
delta.abs() / 2
4444
}
4545

4646
fn delay(&self) -> i64 {

0 commit comments

Comments
 (0)