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)