1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 //go:build unix || (js && wasm) || wasip1
9 // TimespecToNsec returns the time stored in ts as nanoseconds.
10 func TimespecToNsec(ts Timespec) int64 { return ts.Nano() }
12 // NsecToTimespec converts a number of nanoseconds into a Timespec.
13 func NsecToTimespec(nsec int64) Timespec {
20 return setTimespec(sec, nsec)
23 // TimevalToNsec returns the time stored in tv as nanoseconds.
24 func TimevalToNsec(tv Timeval) int64 { return tv.Nano() }
26 // NsecToTimeval converts a number of nanoseconds into a Timeval.
27 func NsecToTimeval(nsec int64) Timeval {
28 nsec += 999 // round up to microsecond
29 usec := nsec % 1e9 / 1e3
35 return setTimeval(sec, usec)