Skip to content

time: Parse should handle Jan 2nd #28841

@seebs

Description

@seebs

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

$ go version
1.11

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"

What 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, ' as nd, '.

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 literal nd, or produce nd 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions