Skip to content

time: unexpected error in Parse when parsing January 31st (day 031) using "002" day of year format #37387

@LDiegoM

Description

@LDiegoM

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

$ go version

go version go1.13.8 darwin/amd64

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"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"

What did you do?

I tried to parse a date with Year + YearDay + Hour format, using time.Parse().
My actual layout is 0600215
I need to parse dates in the especified format to get the corresponding time.Time structure.

Code in playground: https://play.golang.org/p/nhbg1xnT93L

The input parameter to time.Parse() function that shows the issue is: "1803114"

What did you expect to see?

The expected result is a time.Time structure with the date "2018-01-31 14:00:00", and no error.

What did you see instead?

Instead of a time.Time structure, I got a parsing error: parsing time "1803114": day out of range
This happens only for the 031 day of yaer, wich corresponds to January 31st, and it happens both for leap-years and non leap-years.
The rest of the days of year (001 to 030, and 032 to 365) works fine.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions