// Copyright 2017 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 aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris zospackage uniximport// 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 = % 1e9if < 0 { += 1e9 -- }returnsetTimespec(, )}// TimeToTimespec converts t into a Timespec.// On some 32-bit systems the range of valid Timespec values are smaller// than that of time.Time values. So if t is out of the valid range of// Timespec, it returns a zero Timespec and ERANGE.func ( time.Time) (Timespec, error) { := .Unix() := int64(.Nanosecond()) := setTimespec(, )// Currently all targets have either int32 or int64 for Timespec.Sec. // If there were a new target with floating point type for it, we have // to consider the rounding error.ifint64(.Sec) != {returnTimespec{}, ERANGE }return , nil}// 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 := / 1e9if < 0 { += 1e6 -- }returnsetTimeval(, )}// Unix returns the time stored in ts as seconds plus nanoseconds.func ( *Timespec) () ( int64, int64) {returnint64(.Sec), int64(.Nsec)}// Unix returns the time stored in tv as seconds plus nanoseconds.func ( *Timeval) () ( int64, int64) {returnint64(.Sec), int64(.Usec) * 1000}// Nano returns the time stored in ts as nanoseconds.func ( *Timespec) () int64 {returnint64(.Sec)*1e9 + int64(.Nsec)}// Nano returns the time stored in tv as nanoseconds.func ( *Timeval) () int64 {returnint64(.Sec)*1e9 + int64(.Usec)*1000}
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.