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: time.Parse: poor error message for invalid string #4493

Closed
gopherbot opened this issue Dec 5, 2012 · 8 comments
Closed

time: time.Parse: poor error message for invalid string #4493

gopherbot opened this issue Dec 5, 2012 · 8 comments

Comments

@gopherbot
Copy link

@gopherbot gopherbot commented Dec 5, 2012

by guillaume.gvt:

I have encountered a problem while trying to unmarshall time strings from json. In some
cases, the error output is inaccurate.

What steps will reproduce the problem?
1. create a json string containing a time string value.
2. try to unmarshall the json into a struct containing a time.Time var.
3. put a time string that does not match the default format (in my case the error is in
the timezone part), and the error output fails to indicate the error properly.

My test program is available here: http://play.golang.org/p/lIjVVFA1UF

What is the expected output?
parsing time ""2006-01-02T15:04:05Z07:00"" as
""2006-01-02T15:04:05Z07:00"": cannot parse "07:00""
as """

What do you see instead?
parsing time ""2006-01-02T15:04:05Z07:00"" as
""2006-01-02T15:04:05Z07:00"": cannot parse "" as
"""

Which compiler are you using (5g, 6g, 8g, gccgo)?
6g

Which operating system are you using?
Linux 3.2.0-24-generic #39-Ubuntu SMP Mon May 21 16:52:17 UTC 2012 x86_64 x86_64 x86_64
GNU/Linux

Which version are you using?  (run 'go version')
go version go1

Please provide any additional information below.
I have found a fix to get the result i desire, but i am not sure this is the best way to
fix it.
What i did is go to src/pkg/time/format.go and modify the skip function.
I replaced both occurences of `return "", errBad` with `return value, errBad`
@rsc
Copy link
Contributor

@rsc rsc commented Dec 6, 2012

Comment 1:

Z07:00 is the notation we use to mean 'either a Z or �hh:mm'. It is a
time pattern but it is not a valid time. See the bottom of 'godoc time
RFC3339' for more.
This program demonstrates the three valid inputs:
http://play.golang.org/p/Z713W74KF7.

Status changed to WorkingAsIntended.

@gopherbot
Copy link
Author

@gopherbot gopherbot commented Dec 6, 2012

Comment 2 by guillaume.gvt:

I know that the value is invalid, my point is about the accuracy of the error message.
Someone who does not know the RFC will be confused by:
cannot parse "" as """
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Dec 6, 2012

Comment 3:

Labels changed: added priority-later, removed priority-triage.

Status changed to Accepted.

@rsc
Copy link
Contributor

@rsc rsc commented Dec 10, 2012

Comment 4:

Labels changed: added size-m.

@rsc
Copy link
Contributor

@rsc rsc commented Dec 10, 2012

Comment 5:

Labels changed: added suggested.

@shivakumargn
Copy link
Contributor

@shivakumargn shivakumargn commented Feb 3, 2013

Comment 6:

@guillaume, the change to skip() seems indeed the fix.
Would you like to contribute a fix? (http://golang.org/doc/contribute.html)
@rsc
Copy link
Contributor

@rsc rsc commented Feb 4, 2013

Comment 7:

I'll put a change together. The fix is trivial, the testing not as much.
@rsc
Copy link
Contributor

@rsc rsc commented Feb 4, 2013

Comment 8:

This issue was closed by revision 6b4cf2b.

Status changed to Fixed.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.