Skip to content

proposal: syscall,golang.org/x/sys/windows: add and use Filetime.Unix #78339

Description

@alexbrainman

Proposal Details

#74335 reported that time.Unix(0, syscall.Filetime{0, 0}.Nanoseconds()) returns incorrect time in golang.org/x/sys/windows/registry package.

The same problem is present for all syscall.Filetime values that correspond to time between "January 1, 1601 (corresponds to syscall.Filetime{0, 0})" and "January 1, 1970".

CL 682816 fixed the problem in one single place where we use time.Unix(0, syscall.Filetime{...}.Nanoseconds()) by implementing the logic locally, but there are others.

@rsc suggested we add new method

// Unix returns the local Time in sec seconds
// and nsec nanoseconds since January 1, 1601 UTC.
// It is valid to pass the function result
// to time.Unix to convert Filetime ft into time.Time.
func (ft *Filetime) Unix() (sec, nsec int64)

in syscall and golang.org/x/sys/windows packages so new method can be used as

time.Unix(syscall.Filetime{...}.Unix())

I created CL 758981 that contains the proposed change for syscall package as an example.

CC @golang/windows and @gremat (who did all the work in #74335 and CL 682816)

Metadata

Metadata

Assignees

No one assigned

    Labels

    LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposal

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions