From 5adf374967c9f3a6a600a5d83e3467d7a41915b1 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 27 Oct 2017 09:47:47 +0200 Subject: [PATCH] unix: document and move Time{spec,val} methods Add godoc comments for Time{spec,val} methods Unix and Nano. Also move them to timestruct.go to the other Time{spec,val} related functionality. Change-Id: I3b18c5d1bfb235ea4fea25a18fc34b85c21bb365 Reviewed-on: https://go-review.googlesource.com/73871 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- unix/syscall.go | 16 ---------------- unix/timestruct.go | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/unix/syscall.go b/unix/syscall.go index d048da8e..857d2a42 100644 --- a/unix/syscall.go +++ b/unix/syscall.go @@ -49,19 +49,3 @@ func BytePtrFromString(s string) (*byte, error) { // Single-word zero for use when we need a valid pointer to 0 bytes. // See mkunix.pl. var _zero uintptr - -func (ts *Timespec) Unix() (sec int64, nsec int64) { - return int64(ts.Sec), int64(ts.Nsec) -} - -func (tv *Timeval) Unix() (sec int64, nsec int64) { - return int64(tv.Sec), int64(tv.Usec) * 1000 -} - -func (ts *Timespec) Nano() int64 { - return int64(ts.Sec)*1e9 + int64(ts.Nsec) -} - -func (tv *Timeval) Nano() int64 { - return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000 -} diff --git a/unix/timestruct.go b/unix/timestruct.go index e4638246..139fbbeb 100644 --- a/unix/timestruct.go +++ b/unix/timestruct.go @@ -38,3 +38,25 @@ func NsecToTimeval(nsec int64) Timeval { } return setTimeval(sec, usec) } + +// Unix returns ts as the number of seconds and nanoseconds elapsed since the +// Unix epoch. +func (ts *Timespec) Unix() (sec int64, nsec int64) { + return int64(ts.Sec), int64(ts.Nsec) +} + +// Unix returns tv as the number of seconds and nanoseconds elapsed since the +// Unix epoch. +func (tv *Timeval) Unix() (sec int64, nsec int64) { + return int64(tv.Sec), int64(tv.Usec) * 1000 +} + +// Nano returns ts as the number of nanoseconds elapsed since the Unix epoch. +func (ts *Timespec) Nano() int64 { + return int64(ts.Sec)*1e9 + int64(ts.Nsec) +} + +// Nano returns tv as the number of nanoseconds elapsed since the Unix epoch. +func (tv *Timeval) Nano() int64 { + return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000 +}