From aec9a390925b9feece6a6e9b19bdaf177e084ed4 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 11 Dec 2020 11:05:54 +0100 Subject: [PATCH] unix: use Time{spec,val}.Nano in Time{spec,val}ToNsec Follow what CL 188397 did in package syscall: Call the Nano methods of Timespec and Timeval in TimespecToNsec and TimevalToNsec respectively, instead of duplicating the implementation. Change-Id: I50f1958c0f7bca92fc4990684f1de9c148ae5859 Reviewed-on: https://go-review.googlesource.com/c/sys/+/277253 Trust: Tobias Klauser Run-TryBot: Tobias Klauser TryBot-Result: Go Bot Reviewed-by: Ian Lance Taylor --- unix/timestruct.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unix/timestruct.go b/unix/timestruct.go index 6b0a89ad..10360429 100644 --- a/unix/timestruct.go +++ b/unix/timestruct.go @@ -9,7 +9,7 @@ package unix import "time" // TimespecToNSec returns the time stored in ts as nanoseconds. -func TimespecToNsec(ts Timespec) int64 { return int64(ts.Sec)*1e9 + int64(ts.Nsec) } +func TimespecToNsec(ts Timespec) int64 { return ts.Nano() } // NsecToTimespec converts a number of nanoseconds into a Timespec. func NsecToTimespec(nsec int64) Timespec { @@ -41,7 +41,7 @@ func TimeToTimespec(t time.Time) (Timespec, error) { } // TimevalToNsec returns the time stored in tv as nanoseconds. -func TimevalToNsec(tv Timeval) int64 { return int64(tv.Sec)*1e9 + int64(tv.Usec)*1e3 } +func TimevalToNsec(tv Timeval) int64 { return tv.Nano() } // NsecToTimeval converts a number of nanoseconds into a Timeval. func NsecToTimeval(nsec int64) Timeval {