Skip to content

time: Parse has no description of what errors it can generate #32820

Closed as not planned
@weregamer

Description

@weregamer
go version go1.12.5 linux/amd64

This is a comment on the current godoc at https://golang.org/pkg/time/. This godoc does not offer any description of what is or is not an error in parsing.

Some possible errors are pretty obvious - out of range elements, for example (day of year 400, month 13, etc.)

And I do think it's reasonable to expect that you'll get an error if the string doesn't match up very well with the layout you gave (two-digit year instead of four, mismatched punctuation, etc.). But for most packages we seem to be more thorough in explaining border-case errors.

For example, what if the input string has some trailing stuff after the part to be parsed? One could argue that this is a mismatch of the format, and should be an error, or that this is something that should be let slide because you might be parsing just the beginning of a string. Again, I would interpolate the former and expect the caller to do some massaging, but it seems unwise to not be explicit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.help wanted

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions