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: unexpected error in Parse when parsing January 31st (day 031) using "002" day of year format #37387

Closed
LDiegoM opened this issue Feb 23, 2020 · 5 comments

Comments

@LDiegoM
Copy link

@LDiegoM LDiegoM commented Feb 23, 2020

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.

@ianlancetaylor ianlancetaylor changed the title Unexpected error in time.Parse() when parsing January 31st (day 031) using "002" day of year format time: unexpected error in Parse when parsing January 31st (day 031) using "002" day of year format Feb 23, 2020
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Feb 23, 2020

Ouch, thanks for reporting that. I will send a patch.

@gopherbot
Copy link

@gopherbot gopherbot commented Feb 23, 2020

Change https://golang.org/cl/220637 mentions this issue: time: don't get confused about day 31 when parsing 002

@gopherbot gopherbot closed this in 5bd1454 Feb 23, 2020
@emiguens
Copy link

@emiguens emiguens commented Mar 20, 2020

Hi @ianlancetaylor,
Now that 1.14.1 is released I've noticed that this fix was not included. Is this considered a breaking change? should we not expect to see this released until 1.15?
Thanks!

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Mar 20, 2020

This isn't a regression and it doesn't seem likely to affect very many people, it seems unlikely to lead to silen failures, and it's not to hard to work around. Unless we hear of a good reason to backport it, I think it will wait until 1.15.

@emiguens
Copy link

@emiguens emiguens commented Mar 20, 2020

Thanks for answering.
As you've said, we have this issue but we've worked around it for the time being, I was just asking to check about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.