-
Notifications
You must be signed in to change notification settings - Fork 18k
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: Parse should handle Jan 2nd
#28841
Comments
Jan 2nd
Jan 2nd
Could you show a small, complete, example program, perhaps on play.golang.org? Thanks. |
https://play.golang.org/p/uF6c0kO-3ow D'oh, sorry about that. I even had the window still open. :) |
Thanks. I see. I would worry about internationalization. Matching |
Change https://golang.org/cl/150137 mentions this issue: |
Hmm. Does I agree that it might be a bad idea to handle this partially, but it turned out to be easy to write, so I've sent in the code. I will not be in the slightest offended if it's rejected. |
This seems like overreach to me. I'm inclined not to. /cc @robpike |
I'm honestly still not sure how I feel about it. It's way easier than I originally thought it would be, but it's not at all obvious that it's desireable. The big appeal is just that it's a reasonably common written date format. |
This does feel like overreach. Internationalization worries abound as well. |
There seems to be a consensus that we won't be supporting this, so I think we can close this issue. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
used a layout:
Jan 2nd, '06
to parse a time:
Jan 3rd, '06
What did you expect to see?
Ideally, I would love it if this worked.
What did you see instead?
It can't parse
rd, '
asnd, '
.I'm well aware that this may well be a ridiculous edge case, but it seems to me that the specific idiom of writing the weird suffixes on numbers in dates is fairly common, and it's very hard for a naive user, or even a moderately skilled one, to discern correctly where in a string to look for such a suffix.
The reference time makes it possible to reasonably infer that
2nd
implies the format "day of month plus suffix". Given that, it would be reasonably practical to do either of (1) accepting the correct suffixes for the 31 values which can reasonably occur, or (2) accepting any of st/nd/rd/th after a numeric day value. (Given the response to #12728, I'm guessing that the latter would be preferable; this is arguably less of an error than feb 30th is...)I'm honestly not sure it's a good idea. On the other hand, I think the risk is very low -- I doubt anyone has ever written a layout with
2nd
in it with the intent that it match explicitly only the literalnd
, or producend
after every number, and getting it right would look really cool.Being prone to hubris, I'm totally volunteering to try to write this if anyone expresses a willingness to see it merged.
The text was updated successfully, but these errors were encountered: