// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build unix || (js && wasm) || wasip1

package syscall

// TimespecToNsec returns the time stored in ts as nanoseconds.
func ( Timespec) int64 { return .Nano() }

// NsecToTimespec converts a number of nanoseconds into a Timespec.
func ( int64) Timespec {
	 :=  / 1e9
	 =  % 1e9
	if  < 0 {
		 += 1e9
		--
	}
	return setTimespec(, )
}

// TimevalToNsec returns the time stored in tv as nanoseconds.
func ( Timeval) int64 { return .Nano() }

// NsecToTimeval converts a number of nanoseconds into a Timeval.
func ( int64) Timeval {
	 += 999 // round up to microsecond
	 :=  % 1e9 / 1e3
	 :=  / 1e9
	if  < 0 {
		 += 1e6
		--
	}
	return setTimeval(, )
}