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

Comments

@vsekhar
Copy link
Contributor

@vsekhar 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

@andybons andybons commented Aug 11, 2020

@andybons andybons added this to the Unplanned milestone Aug 11, 2020
@ALTree
Copy link
Member

@ALTree 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 Aug 11, 2020
@vsekhar
Copy link
Contributor Author

@vsekhar vsekhar commented Aug 12, 2020

🤦 Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.