-
Notifications
You must be signed in to change notification settings - Fork 18k
time: document behaviour of Parse in the presence of >9 fractional second digits #50806
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
Can you suggest how the documentation should be changed? Thanks. |
I haven't looked into this fully, but I know that the behaviour pre CL 353713 caused some such inputs to My only suggestion therefore would be to add some appropriate wording to https://pkg.go.dev/time@go1.18beta1#Parse that explains the new behaviour. As I mentioned above, I very much defer to you/others on whether this change in behaviour warrants a mention in the release notes that references the https://pkg.go.dev/time@go1.18beta1#Parse docs I propose. |
Here is an example that causes an error with Go 1.17: fmt.Println(time.Parse(time.RFC3339, "2021-09-29T16:04:33.100000000001Z")) With Go 1.17 this prints
With Go tip this prints
This seems clearly better. But I don't know how to document this except to say something like "fractional seconds that are too small to represent in a Time value are ignored." Does that seem like a useful addition? |
To put it another way, to me this seems to be clearly a bug fix. It's difficult for me to imagine that anybody relied on the error they got from using 10 or more digits in the fractional part. Especially since this, for example, does not give an error with Go 1.17, but instead returns the wrong result. fmt.Println(time.Parse(time.RFC3339, "2021-09-29T16:04:33.000100000001Z")) 1.17:
tip:
|
Yes, something like that would work well.
Agreed.
Good point, thanks for that example. The small doc change still seems worthwhile to my mind, but I totally defer to your judgement, especially with the 1.18 release not far away. |
I see this as a bug fix rather than a behavior change as such, so I don't think it needs to be explicitly called out in the release notes. I'll send a patch for the docs. |
Change https://golang.org/cl/381155 mentions this issue: |
👍
I just +1-ed. I'll defer to someone who owns the package to +2. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://go-review.googlesource.com/c/go/+/353713/ made a change to
Parse()
to truncate fractional seconds longer than 9 digits.I defer to others on whether truncating, rounding or error-ing is the "right" answer here, but I think a doc update is in order whatever the conclusion. As was pointed out in #48685, certain such inputs resulted in an error prior to CL 353713, and some people might have been relying on that behaviour.
What did you expect to see?
https://pkg.go.dev/time@go1.18beta1 to mention of the behaviour when
>9
fractional second digits are provided.Such a change might also warrant a mention in the release notes, given the behaviour change.
What did you see instead?
As it stands https://pkg.go.dev/time@go1.18beta1 makes no mention.
CC @rsc via https://dev.golang.org/owners
CC @AlexanderYastrebov and @jtbandes from #48685
The text was updated successfully, but these errors were encountered: