Skip to content
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: ParseInLocation panics if no Location specified #25646

Closed
mlindnerIDT opened this issue May 30, 2018 · 1 comment
Closed

time: ParseInLocation panics if no Location specified #25646

mlindnerIDT opened this issue May 30, 2018 · 1 comment

Comments

@mlindnerIDT
Copy link

mlindnerIDT commented May 30, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.10 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/mlindner/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/mlindner/gocode"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
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"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/bx/wsy1g9fd10959r8nq8fmrzw80000gp/T/go-build930815221=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

https://play.golang.org/p/QyoSve9DTpt

pass ParseInLocation a string that does not specify a location, and don't provide a location explicitly.

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?

I expected it to see it default to UTC, as per documentation:
First, in the absence of time zone information, Parse interprets a time as UTC;
Since "loc" is a *Location, nil should be a valid location. I understand that it may be also be interpreted that there must be a location in the string and format, or in the location provided, but at least one must be provided. However, that is not stated nor implied by the documentation or the code.

What did you see instead?

panic: time: missing Location in call to Date

goroutine 1 [running]:
time.Date(0x7e2, 0x5, 0x1e, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/usr/local/go/src/time/time.go:1313 +0x720
time.parse(0x11239f, 0xa, 0x10ff02, 0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/usr/local/go/src/time/format.go:1094 +0x2ca0
time.ParseInLocation(0x11239f, 0xa, 0x10ff02, 0xa, 0x0, 0x1a4780, 0x0, 0x0, 0x0, 0x0, ...)
/usr/local/go/src/time/format.go:783 +0xa0
main.main()
/tmp/sandbox728893309/main.go:13 +0x80

I believe the problem is in format.go, line 783, which reads:
return parse(layout, value, loc, loc)

and should (I believe) read:

    if loc {
        return parse(layout, value, loc, loc)
    } else {
        return parse(layout, value, UTC, loc)
    }
@ianlancetaylor
Copy link
Contributor

I think you are misreading the documentation. It says First, in the absence of time zone information, Parse interprets a time as UTC; ParseInLocation interprets the time as in the given location. The part about "absence of time zone information" refers to Parse, not ParseInLocation. ParseInLocation does require a location to be given in the absence of time zone information.

Closing because I think this is working as documented. Please comment if you disagree.

@golang golang locked and limited conversation to collaborators May 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants