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

Closed
larsklingsten opened this issue Nov 10, 2016 · 8 comments

Comments

Projects
None yet
7 participants
@larsklingsten
Copy link

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)?

OARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/larsklingsten/source/golang"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7.3/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7.3/libexec/pkg/tool/darwin_amd64"
CC="clang"
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
mmon"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

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

// see -> https://play.golang.org/p/FvCKKNbPK5

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

@robpike

This comment has been minimized.

Copy link
Contributor

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

@larsklingsten

This comment has been minimized.

Copy link
Author

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)

(https://play.golang.org/p/o9lQ_TBTZH)

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

@lucasalcantara

This comment has been minimized.

Copy link

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

@quentinmit

This comment has been minimized.

Copy link
Contributor

commented Nov 16, 2016

@lucasalcantara Feel free to send a CL

@bradfitz

This comment has been minimized.

Copy link
Member

commented Nov 21, 2016

@lucasalcantara, status?

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

@lucasalcantara

This comment has been minimized.

Copy link

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

@odeke-em

This comment has been minimized.

Copy link
Member

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.

@odeke-em

This comment has been minimized.

Copy link
Member

commented Nov 22, 2016

Oops, the Gobot hadn't tagged this issue so I mailed a dupe CL https://go-review.googlesource.com/c/33434, @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.
You can’t perform that action at this time.