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: ParseTime layouts with underscores _ #21966

Closed
FlorianUekermann opened this issue Sep 21, 2017 · 2 comments
Closed

time: ParseTime layouts with underscores _ #21966

FlorianUekermann opened this issue Sep 21, 2017 · 2 comments

Comments

@FlorianUekermann
Copy link
Contributor

@FlorianUekermann FlorianUekermann commented Sep 21, 2017

I suspect this has been mentioned before, but my searches came up empty.

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

This fmt.Println(time.Parse("2006-_1-_2", "2017-7-17")) fails with this 0001-01-01 00:00:00 +0000 UTC parsing time "2017-7-17" as "2006-_1-_2": cannot parse "7-17" as "-_" output.

I naively expected _-parsing to be less greedy. I'm not sure if this is supposed to work, but maybe it is worth fixing anyway.

@ianlancetaylor ianlancetaylor added this to the Go1.10 milestone Sep 21, 2017
@robpike
Copy link
Contributor

@robpike robpike commented Sep 22, 2017

"Within the format string, an underscore _ represents a space that may be replaced by a digit if the following number (a day) has two digits; for compatibility with fixed-width Unix time formats."

I read that as "working as intended."

@FlorianUekermann
Copy link
Contributor Author

@FlorianUekermann FlorianUekermann commented Sep 22, 2017

I misunderstood the meaning of the word space here. Sorry about that. That was a bit stupid, the docs are actually quite clear. Just removing the underscores has the desired effect.

@golang golang locked and limited conversation to collaborators Sep 22, 2018
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.