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

Closed
tredoe opened this issue Jan 24, 2019 · 2 comments

Comments

Projects
None yet
3 participants
@tredoe
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?

Yes

What did you do?

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

https://play.golang.org/p/maXaDx3GZ-V

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"

@bcmills

This comment has been minimized.

Copy link
Member

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

@gopherbot

This comment has been minimized.

Copy link

commented Jan 30, 2019

Change https://golang.org/cl/160338 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
Reviewed-on: https://go-review.googlesource.com/c/go/+/160338
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
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.