Skip to content

proposal: time: add IsUnixEpoch method to test whether a time is the Unix epoch #46974

@joshbradshaw11

Description

@joshbradshaw11
$ go version

go version go1.15.6 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

This is just an opinion, but I think that the the time library should provide a simpler method for getting the Epoch time.

I was surprised by this:

t := time.Unix(int64(0), 0)
log.Println("Time is ", t.String())
log.Println("Is time zero: ", t.IsZero())
log.Println("Is time epoch: ", t == time.Unix(int64(0), 0))
Time is  1969-12-31 19:00:00 -0500 EST
Is time zero:  false
Is time epoch:  true

Upon further inspection I realized that I needed to do time.Unix(0, 0).UTC() to get the epoch value because time.Unix() is timezone aware. Given that the API already has a time.isZero() method, I think there should be a method for fetching the environment's epoch value directly, without using a parsing method or a timezone aware method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions