Skip to content

time.Parse("Jan 2, 2006", "Dec 4, 2019 11:14:25") returns an "extra text" error but does not even partially populate the time return value #45195

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

Closed
rbucker opened this issue Mar 24, 2021 · 1 comment

Comments

@rbucker
Copy link

rbucker commented Mar 24, 2021

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

$ go version
1.16.2

Does this issue reproduce with the latest release?

YES

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/rbucker/.cache/go-build"
GOENV="/home/rbucker/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/rbucker/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/rbucker/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/rbucker/bin/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/rbucker/bin/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.2"
GCCGO="gccgo"
AR="gcc-ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1925909121=/tmp/go-build -gno-record-gcc-switches"

What did you do?

time.Parse("Jan 2, 2006", "Dec 4, 2019 11:14:25")

https://play.golang.org/p/8RN0EnD2NMB

What did you expect to see?

I'm thinking about the OS file exists test where one has to test the err to determine what type of file... or something like that, however, it would be better if the time variable was filled with whatever had been collected to that point.

What did you see instead?

the default time value.

@ianlancetaylor
Copy link
Contributor

I'm not sure what to say except: you're right. If time.Parse is unable to parse the date, then it returns an error and an empty time.Time value. That is how the function has worked since it was written, and changing it now would be more likely to introduce problems rather than fix them.

@golang golang locked and limited conversation to collaborators Mar 24, 2022
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