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: wrong error message at parsing years #29916

tredoe opened this issue Jan 24, 2019 · 2 comments


None yet
3 participants
Copy link

commented Jan 24, 2019

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

$ go version
go version go1.11.4 darwin/amd64

Does this issue reproduce with the latest release?


What did you do?

Parsing the year-month "111-01" with layout "2006-01"

What did you expect to see?

At the last part of the error i=2: cannot parse "111" as "2006"

What did you see instead?

cannot parse "01" as "2006"


This comment has been minimized.

Copy link

commented Jan 29, 2019

This is quite likely the same underlying problem as #29918. Closing as a duplicate.

@bcmills bcmills closed this Jan 29, 2019


This comment has been minimized.

Copy link

commented Jan 30, 2019

Change mentions this issue: time: fix misleading error for leading zero format

gopherbot pushed a commit that referenced this issue Apr 26, 2019

time: fix misleading error with the leading zero format
When the leading zero format is used, we currently don't handle the
month and year properly.

For the month, we were reporting an out of range error when getnum
returns zero of its own, as it also returns the month 0. That's
confusing, so only check the range when getnum returns a nil error.

For the year, we don't restore the value when parsing error occurs. For
example, with the incorrect input "111-01", "01" will be used to report
an error. So restore the value when an error occurs fix the problem.

Fixes #29918
Fixes #29916

Change-Id: I3145f8c46813a0457766b7c302482e6b56f94ed6
Run-TryBot: Ian Lance Taylor <>
TryBot-Result: Gobot Gobot <>
Reviewed-by: Ian Lance Taylor <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.