Skip to content

time: Unix(sec, nanonsec) has bizarre undocumented behavior for large values of sec #10906

@maxpoletto

Description

@maxpoletto

The biggest value that can be passed as the first parameter of time.Unix(seconds, nanos) is
math.MaxInt64 - 62135596800. Sample code: http://play.golang.org/p/Ck5Ny1W-ud

62135596800 is the number of seconds, accounting for leap days, that separate the start of the Go internal epoch (year 1) from the start of the Unix epoch (1970).

time.Unix() should not leak its implementation details in this way, or else the behavior should be clearly documented.

It does not seem unreasonable, given the current spec/docs, for someone to create a time.Unix(math.MaxInt64, 0) as a sentinel value, but this leads to strange and hard-to-debug behavior.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions