Skip to content

x/sys/unix: Can not convert time.Time to Timespec in portable way #23078

@xry111

Description

@xry111

What version of Go are you using (go version)?

go version go1.9.2 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/xry111/go"
GORACE=""
GOROOT="/opt/google-go"
GOTOOLDIR="/opt/google-go/pkg/tool/linux_amd64"
GCCGO="/usr/bin/gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build074259031=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config

What did you do?

I want to convert a time.Time to unix.Timespec. But there is no portable way to do that.

What did you expect to see?

We should have a way to convert time.Time to unix.Timespec cleanly.

What did you see instead?

The only factory of Timespec is NsecToTimespec. This certainly lead to year 2262 problem.

Then I tried

// t is a time.Time
ts := unix.Timespec{
    Sec: t.Unix(),
    Nsec: t.Nanosecond(),
}

This fails with type mismatch. More seriously, the types of Timespec.Sec and Timespec.Nsec differ on platforms. Now I have no idea how can I generate a unix.Timespec from time.Time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.help wanted

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions