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: Parse does not detect bad days ("00" -> returns wrong date && err=nil) #17874

larsklingsten opened this issue Nov 10, 2016 · 8 comments


Copy link

@larsklingsten larsklingsten commented Nov 10, 2016

Please answer these questions before submitting your issue. Thanks!

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

go version go1.7.3 darwin/amd64

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

GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/qc/2q_p2_zd32g_2lz3v5w8yclw0000gn/T/go-build111275672=/tmp/go-build -gno-record-gcc-switches -fno-co

What did you do?

v, err := time.Parse("02.01.2006", "00.01.1970")
fmt.Println(v, err)

// see ->

What did you expect to see?

0001-01-01 00:00:00 +0000 UTC

What did you see instead?

1969-12-31 00:00:00 +0000 UTC

@bradfitz bradfitz changed the title time.Parse(format, date) -> does not detect bad days ("00" -> returns wrong date && err=nil time: Parse does not detect bad days ("00" -> returns wrong date && err=nil) Nov 10, 2016
Copy link

@robpike robpike commented Nov 10, 2016

Working as intended. As the docs say,

No checking is done that the day of the month is within the month's valid
dates; any one- or two-digit value is accepted. For example February 31 and
even February 99 are valid dates, specifying dates in March and May. This
behavior is consistent with time.Date.
@robpike robpike closed this Nov 10, 2016
Copy link

@larsklingsten larsklingsten commented Nov 11, 2016

Thanks for very swift reply, appreciated.

Mentioned "31" and "99" for February does return "day out of range" error (as expected) . "00" instead overflows in the previous month with 'nil' error (unexpected)


parse(...) DOES evaluate the validity of the day of the month.
// Validate the day of the month.
if day > daysIn(Month(month), year) {
return Time{}, &ParseError{alayout, avalue, "", value, ": day out of range"}

time.Parse("02.01.2006", "29.02.1970") -> returns "day out of range" error
time.Parse("02.01.2006", "00.01.1970") -> "1969-12-31 00:00:00 +0000 UTC"

This "00" overflowing from "00.01.1970" into "31.12.1969" with 'nil' error appears - to me - inconsistent.

@robpike robpike reopened this Nov 11, 2016
Copy link

@lucasalcantara lucasalcantara commented Nov 14, 2016

Can I work on it?

@quentinmit quentinmit added the NeedsFix label Nov 16, 2016
@quentinmit quentinmit added this to the Go1.8Maybe milestone Nov 16, 2016
Copy link

@quentinmit quentinmit commented Nov 16, 2016

@lucasalcantara Feel free to send a CL

Copy link

@bradfitz bradfitz commented Nov 21, 2016

@lucasalcantara, status?

Alternatively, anybody else (including @robpike) is welcome to send a CL.

Copy link

@lucasalcantara lucasalcantara commented Nov 21, 2016

@bradfitz sorry brad, my pc broke and will take a while to fix. So anyone can get this. I forgot to comment in here.

@bradfitz bradfitz self-assigned this Nov 22, 2016
Copy link

@odeke-em odeke-em commented Nov 22, 2016

I can take this on, I've got the bandwidth and I've just prepared a CL for it, about to mail it.

Copy link

@odeke-em odeke-em commented Nov 22, 2016

Oops, the Gobot hadn't tagged this issue so I mailed a dupe CL, @bradfitz's is ready to go, so I'll abandon mine :)

@gopherbot gopherbot closed this in 323b5c9 Nov 22, 2016
@golang golang locked and limited conversation to collaborators Nov 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants
You can’t perform that action at this time.