Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time: UnixNano thinks year 1 comes after 1720 #40702

Closed
vsekhar opened this issue Aug 11, 2020 · 3 comments
Closed

time: UnixNano thinks year 1 comes after 1720 #40702

vsekhar opened this issue Aug 11, 2020 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@vsekhar
Copy link
Contributor

vsekhar commented Aug 11, 2020

UnixNano gives inconsistent results. Specifically, it believes the year 1 comes after the year 1720.

package main

import (
	"fmt"
	"time"
)

func main() {
	t1 := time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)
	t2 := time.Date(1720, 12, 30, 0, 0, 0, 0, time.UTC)
	t3 := time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC)	
	
	fmt.Printf("%s: %d\n", t1, t1.UnixNano())
	fmt.Printf("%s: %d\n", t2, t2.UnixNano())
	fmt.Printf("%s: %d\n", t3, t3.UnixNano())
}
0001-01-01 00:00:00 +0000 UTC: -6795364578871345152
1720-12-30 00:00:00 +0000 UTC: -7857820800000000000
1970-01-01 00:00:00 +0000 UTC: 0

https://play.golang.org/p/XrtNdpfNFk1

@andybons
Copy link
Member

@ianlancetaylor

@andybons andybons added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 11, 2020
@andybons andybons added this to the Unplanned milestone Aug 11, 2020
@ALTree
Copy link
Member

ALTree commented Aug 11, 2020

You can't call UnixNano on a date before the year 1678; this is clearly documented:

https://golang.org/pkg/time/#Time.UnixNano

UnixNano returns t as a Unix time, the number of nanoseconds elapsed since January 1, 1970 UTC. The result is undefined if the Unix time in nanoseconds cannot be represented by an int64 (a date before the year 1678 or [...] )

So your t1.UnixNano() call is not valid.

@ALTree ALTree closed this as completed Aug 11, 2020
@vsekhar
Copy link
Contributor Author

vsekhar commented Aug 12, 2020

🤦 Thanks.

@golang golang locked and limited conversation to collaborators Aug 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants