-
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: Round(0), Truncate(0) strip monotonic clock readings but documentation still says it returns t unchanged #21485
Comments
m=+0.000241395
m=+0.000241395
m=+0.000241395
m=+0.000241395
As the comment says, this is an intentional change, because without it you can have two It would be hard to change it at this point in the release process. At the least we would want to hear whether anybody else is reporting a breakage. This is the first problem report I've seen on this. CC @rsc |
Ah. I think I should probably start serializing the monotone part as well....since the typically check on serialization correctness is to compare for equality with the original value after serialization and deserializing... hmm. Or start inserting StripMono() calls. Since it looks like its inevitable, this would be helpful for patching code that wants to use 1.9: Perhaps stripMono() could be exported? I've developed the following workaround, but its a rather elaborate and an extra function call when stripMono() could simply be StripMono().
Actually it looks like Truncate(0) might be a single function call to
Or not. Actually, I'm reconsidering. It would make more sense to keep And just simply export |
Importantly, time package documentation says in multiple places that the I don't be think you can rely on Stringer output not changing between any Go versions. That would be akin to using @dsnet gave a very informative talk on this subject at this year's GopherCon, see https://www.youtube.com/watch?v=OuT8YYAOOVI. |
I see that the go1.9rc2 time API documentation does recommend using
However the documentation for Round itself belies this, also claiming at https://github.com/golang/go/blob/master/src/time/time.go#L1403 that
|
Meta: The |
On the topic of |
This issue of As @shurcooL mentioned, |
All this is true, but if you write Round(0) then it will work in Go 1.8, so we avoid bifurcating the world of compiling Go programs. |
@rsc Very good rationale. Thanks for pointing that out. |
@dsnet This bug points out two important documentation fixes that should be made. Since you seem in a hurry to close it, would you mind opening a new bug to note the needed doc fixes to time.Round and time.Truncate? Both claim they are unchanged with a zero argument, but that is no longer true in 1.9. |
m=+0.000241395
I'll mention https://talks.godoc.org/github.com/davecheney/go-1.9-release-party/presentation.slide#26 here too, since it's relevant to the topic in the original issue. /cc @davecheney |
Change https://golang.org/cl/56690 mentions this issue: |
@shurcooL the CL looks nice, thanks for doing it. It is probably worth reiterating one additional note in the
|
@glycerine Ive considered doing that, but saw that it wouldn't be helpful. If the user doesn't already know Round(0) is the canonical way to strip mono, they won't be able to jump to its documentation to learn that. It's better to leave the rest of time package docs to say Round(0) is canonical. Other ways are valid too. |
What will happen is this: user sees call to Round(0) in some code they haven't written themselves. Question occurs to user: what the heck is this Round(0) call doing? It doesn't make any sense!?! Let's look at the documentation for Round! User positions cursor over the Round(0) call and presses F12 (or whatever godef is bound to), and jumps to the documentation for Round. Now does the user get a clue? They could, if we help them out here. Or we could just leave them mystified. I'm not saying remove anything. I'm just saying we should add to the Round documentation that one sentence to explain Round(0); in addition to the preamble stuff. Come on. Let's not be stingy with docs. This is crappy API, as rsc agreed. Let's help all we can. |
Yes, the docs will say:
So the user will know that |
Re-opening for cherry-pick. |
CL 56690 OK for Go 1.9.2 (doc fix). |
Change https://golang.org/cl/70846 mentions this issue: |
…avior for d <= 0 Saying that they return t unchanged is misleading, because they return a modified t, stripped of any monotonic clock reading, as of Go 1.9. Fixes #21485. Change-Id: Icddf8813aed3d687fcefcd2fe542829438be6a0a Reviewed-on: https://go-review.googlesource.com/56690 Reviewed-by: Avelino <t@avelino.xxx> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-on: https://go-review.googlesource.com/70846 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Russ Cox <rsc@golang.org>
go1.9.2 has been packaged and includes: The release is posted at golang.org/dl. — golang.org/x/build/cmd/releasebot, Oct 26 21:09:07 UTC |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.9rc2 darwin/amd64
this does not happen, for contrast, with go1.8.3 darwin/amd64
This change is documented at the top of the new go1.9rc2 time/time.go file:
This is actually a rather drastic proposed change. I refer not the use of the monotone clock, but the display of it in timestamps formated via String(). Many of us use String() for many purposes other than debugging. For debugging, a separate new StringWithMonotone() should be provided.
What operating system and processor architecture are you using (
go env
)?go env:
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/jaten/go"
GORACE=""
GOROOT="/usr/local/go1.9rc2"
GOTOOLDIR="/usr/local/go1.9rc2/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/6s/zdc0hvvx7kqcglg5yqm3kl4r0000gn/T/go-build055854381=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
What did you do?
Here code to reproduce the issue,
serialize_time.go
. It is extracted from the time.Time serialization in a popular msgpack serialization package. e.g. getunix() and putunix() are here https://github.com/tinylib/msgp/blob/ad0ff2e232ad2e37faf67087fb24bf8d04a8ce20/msgp/integers.go#L113In summary, in go1.9rc2, time.Time.String() may produce:
2017-08-16 18:41:39.184829495 -0400 EDT m=+0.057013769
whereas in go1.83, the String() applied to the same value produces always:
2017-08-16 18:41:39.184829495 -0400 EDT
While not a language consistency issue, this is a backwards-compatibility issue for programs that expected one thing from their time.Time values. For example, my tests in a fork of the tinylib/msgp lib cited above are suddenly broken under go1.9rc2. So these changes may break many programs unexpectedly when moving from go1.8.3 to go1.9.
I'm glad for the new monotonic time feature under the covers, as it solves bugs with walltime going through leap seconds, but does it have to surface itself into the string representation of time in a non-backcompatible way? For the new info, how about adding a separate stringification method if one needs both timestamps? Perhaps: StringWithMonotone() alongside the old fashioned String().
In summary, while useful, features meant for debugging the new time.Time values should not break backwards compatibility, when they can trivially be provided alongside in a separate new method.
The text was updated successfully, but these errors were encountered: