mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
The various conversion functions just change the format of time values. They don't use the Unix epoch. Although in practice the values are often times since the Unix epoch, they aren't always, so referring to the epoch can be confusing. Fixes #43010 Change-Id: I640d665f0d2017f0974db05d70858037c7c91eda Reviewed-on: https://go-review.googlesource.com/c/go/+/277073 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
36 lines
988 B
Go
36 lines
988 B
Go
// 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.
|
|
|
|
// +build aix darwin dragonfly freebsd js,wasm linux netbsd openbsd solaris
|
|
|
|
package syscall
|
|
|
|
// TimespecToNSec returns the time stored in ts as nanoseconds.
|
|
func TimespecToNsec(ts Timespec) int64 { return ts.Nano() }
|
|
|
|
// NsecToTimespec converts a number of nanoseconds into a Timespec.
|
|
func NsecToTimespec(nsec int64) Timespec {
|
|
sec := nsec / 1e9
|
|
nsec = nsec % 1e9
|
|
if nsec < 0 {
|
|
nsec += 1e9
|
|
sec--
|
|
}
|
|
return setTimespec(sec, nsec)
|
|
}
|
|
|
|
// TimevalToNsec returns the time stored in tv as nanoseconds.
|
|
func TimevalToNsec(tv Timeval) int64 { return tv.Nano() }
|
|
|
|
// NsecToTimeval converts a number of nanoseconds into a Timeval.
|
|
func NsecToTimeval(nsec int64) Timeval {
|
|
nsec += 999 // round up to microsecond
|
|
usec := nsec % 1e9 / 1e3
|
|
sec := nsec / 1e9
|
|
if usec < 0 {
|
|
usec += 1e6
|
|
sec--
|
|
}
|
|
return setTimeval(sec, usec)
|
|
}
|