-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed as not planned
Labels
Description
Go version
go version go1.22.3 darwin/arm64
Output of go env in your module/workspace:
GO111MODULE='on'
GOARCH='arm64'
GOOS='darwin'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:
a, err := time.Parse("2006-21-01", "2024-23-03")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 and 02 could be treated as Month
Lines 123 to 124 in 5bf8c0c
| DateTime = "2006-01-02 15:04:05" | |
| DateOnly = "2006-01-02" |
What did you see happen?
https://go.dev/play/p/qnIFX3Q_zUL
1 January 1 parsing time "2024-23-03" as "2006-21-01": cannot parse "-03" as "1"
2006-01-02What 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.