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
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@larsklingsten
Copy link

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
Copy link
Contributor

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 as completed Nov 10, 2016
@larsklingsten
Copy link
Author

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)

(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
Copy link

Can I work on it?

@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Nov 16, 2016
@quentinmit quentinmit added this to the Go1.8Maybe milestone Nov 16, 2016
@quentinmit
Copy link
Contributor

@lucasalcantara Feel free to send a CL

@bradfitz
Copy link
Contributor

@lucasalcantara, status?

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

@lucasalcantara
Copy link

@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
Copy link
Member

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
Copy link
Member

odeke-em 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 :)

@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.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

7 participants