Skip to content

proposal: x/sys/unix: add methods to convert between time.Time and unix.PtpClockTime on Linux #70032

Open
golang/sys
#230
@yarikk

Description

@yarikk

Proposal Details

Recently we have exposed the syscalls and types related to PTP (IEEE 1588) on Linux in the unix package.
Amongs those is a struct representing time in PTP calls, unix.PtpClockTime. Semantically it is very similar to Unix time, differing in underlying type for the nanoseconds field and having a placeholder for future extentions.

The proposal is to add the convenience methods to carry conversion between unix.PtpClockTime and time.Time:

package unix

func TimeToPtpClockTime(t time.Time) PtpClockTime
func (t *PtpClockTime) Time() time.Time
func (t *PtpClockTime) Unix() (sec int64, nsec int64)

This shall allow to use the maths of the standard time package while avoiding
the boilerplate: write ptpt.Time() instead of time.Unix(ptpt.Sec, int64(ptpt.Nsec)),
and unix.TimeToPtpClockTime(t) instead of unix.PtpClockTime{Sec: t.Unix(), Nsec: uint32(t.Nanosecond())}.

As an example of what the boilerplate looks like in real-world code, please see facebook/time#418.

golang/sys#230 implements the proposal.

Thank you for consideration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    • Status

      Active

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions