-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: documentation shows incorrect formatting of RFC3339 that does not parse #22135
Comments
Dup of #9346? |
@ianlancetaylor #9346 was "frozen due to age" so PLEASE do not close this issue in favor of that other issue. I would like to keep this issue open since it doesn't seem like the other issue was resolved and we can't comment on it now since it was frozen due to age. So I see two issues here:
If the second bullet point doesn't hold, then
I should be able to read this file back in and Parse back my time strings into time objects so I can use them. If I cannot, then time.Parse is risky and not useful for serialization. Even if this just applies to RFC3339, I really feel that we should fix this edge case/bug in RFC3339. Thoughts? I'm happy to help with a PR for a doc or code change if somebody can point me in the right direction as to how to get started. Thanks! :-) |
Your second bullet point does not hold. In general The best way to serialize and deserialize Edit: Fixed typo in URL. |
@ianlancetaylor thanks for responding. When you say "in general, Parse and Format are not inverses of each other", that alarms me. If that's the case, then what's the point of those methods? What is If you're suggesting that I use Sorry, I'm not trying to be harsh here, but I'm really surprised to hear that Thanks again, and I really appreciate your feedback and the work of the go team! Best, Joel |
The point of the If you want to define your own format to interoperate with a non-Go program, then define that format. You should be able to design a format that can use By the way, I took a closer look at your program, and you are trying to use |
@ianlancetaylor thanks for replying. You're right, I did mixup the order of the layout and the value to be parsed (I'd argue that since
Now the output is as follows:
So now the roundtrip within go DOES succeed (yay!) but the sentinel example given in the godoc Where does the godoc say that "the point of the Format method and Parse function is for producing and parsing human-readable time strings"? I disagree that "this is not how they are documented". The documentation of the So maybe the confusion was the the value given in
is NOT actually representative of the values produced by I'm really not trying to be a PITA here, but I did find this confusing and was very surprise by go's behavior here and I just want to prevent others from having the same confusion. Thanks again for your help! :-) |
Yes, it is confusing, and there have been many dups of #9346.
Fixes to the docs are always welcome, but make sure they are correct. |
OK, I'll take a look next week when I have time ... Is there a procedure for updating the official godocs? Thanks! |
Thanks. It's just like contributing source code: https://golang.org/doc/contribute.html |
Change https://golang.org/cl/74231 mentions this issue: |
Change https://golang.org/cl/74890 mentions this issue: |
Updates #9346 Updates #22135 Change-Id: I7039c9f7d49600e877e35b7255c341fea35890e2 Reviewed-on: https://go-review.googlesource.com/74890 Reviewed-by: Rob Pike <[email protected]>
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.8.3 darwin/amd64
Does this issue reproduce with the latest release?
Yes, as far as I know.
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/joel/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/mz/tzh0vwxd08jgh0lx24v39gx40000gn/T/go-build013964967=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
What did you do?
Look at the documentation for the go time package at https://golang.org/pkg/time/#pkg-constants where you'll see:
Now, run the following program:
You will get the following output:
This is a clear and strong violation of the principle of least surprise. It is a strong expectation of go coders that the following loop will work:
If I format a time into a string according to some format F, then I attempt to parse that untouched string using the format F I should ALWAYS be able to parse it back into the original time (or at least something equivalent where
Parse(t.Format(F), F)
does NOT error.If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
What did you expect to see?
Parsing a time string you just formatted should successfully parse.
What did you see instead?
Parsing a time string you just formatted errors. Moreover, the godoc documentation for RFC3339 shows a sentinel format example that does not match actual output.
The text was updated successfully, but these errors were encountered: