-
Notifications
You must be signed in to change notification settings - Fork 18k
time: Parse formats allow ambiguity #67750
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
Comments
That's the wrong layout to use.
Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only. For questions please refer to https://github.com/golang/go/wiki/Questions |
Ok, I reread the Layout comment and it has some handy things about Day and Month: Lines 60 to 62 in 5bf8c0c
saying month is always And it works, correctly returning the 23 of March, but |
Where did you encounter yyyy-dd-mm dates? When we accepted #48801, we believed they were exceedingly rare. |
Go version
go version go1.22.3 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
Time Parse always assumes RFC3339 date and does not allow to change it.
For example https://go.dev/play/p/1gWqncWgd0_h:
expected to parse the date as 23 March 2024, but fails with error
parsing time "2024-23-03" as "2006-21-01": cannot parse "-03" as "1"
Moreover, time.DateOnly format (as well as time.DateTime) assume RFC3339 with ambiguity to anyone who does not follow the RFC, as both
01
and02
could be treated as Monthgo/src/time/format.go
Lines 123 to 124 in 5bf8c0c
What did you see happen?
https://go.dev/play/p/qnIFX3Q_zUL
What did you expect to see?
Expect
time.Parse
to follow the format provided without hidden assumptions leading to errors.Expect time.DateOnly and time.DateTime to provide self-explanatory format without ambiguity.
The text was updated successfully, but these errors were encountered: