From d2380f25b3d3e2f96328b46d1849cf817751ee8b Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Sat, 9 Dec 2023 17:44:02 +0100 Subject: [PATCH] Fix incorrect comment in rtptime.go. Also use Duration.Abs. --- rtptime/rtptime.go | 3 +-- rtptime/rtptime_test.go | 5 +---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/rtptime/rtptime.go b/rtptime/rtptime.go index a824708..9af5573 100644 --- a/rtptime/rtptime.go +++ b/rtptime/rtptime.go @@ -10,10 +10,9 @@ import ( var epoch = time.Now() // FromDuration converts a time.Duration into units of 1/hz. -// Negative values are clamped to zero. func FromDuration(d time.Duration, hz uint32) int64 { if d < 0 { - return -FromDuration(-d, hz) + return -FromDuration(d.Abs(), hz) } hi, lo := bits.Mul64(uint64(d), uint64(hz)) q, _ := bits.Div64(hi, lo, uint64(time.Second)) diff --git a/rtptime/rtptime_test.go b/rtptime/rtptime_test.go index 23dc6fb..00c4f6e 100644 --- a/rtptime/rtptime_test.go +++ b/rtptime/rtptime_test.go @@ -82,10 +82,7 @@ func TestNTP(t *testing.T) { now2 := NTPToTime(ntp) ntp2 := TimeToNTP(now2) - diff1 := now2.Sub(now) - if diff1 < 0 { - diff1 = -diff1 - } + diff1 := now2.Sub(now).Abs() if diff1 > time.Nanosecond { t.Errorf("Expected %v, got %v (diff=%v)", now, now2, diff1)