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: one-digit hour is accepted for 15:04:05 template #29911

Open
tredoe opened this Issue Jan 24, 2019 · 5 comments

Comments

Projects
None yet
3 participants
@tredoe
Copy link

commented Jan 24, 2019

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

$ go version
go version go1.11.4 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

https://play.golang.org/p/EBxIIXatR1Y

What did you expect to see?

I expected to see an error at parsing the time "3:04:05" for layout "15:04:05", of the same way that it fails at parsing the minutes ("03:4:05") or the seconds ("03:04:5").

What did you see instead?

No error.

@mattn

This comment has been minimized.

Copy link
Member

commented Jan 24, 2019

@tredoe

This comment has been minimized.

Copy link
Author

commented Jan 24, 2019

I want not to accept hours, minutes neither seconds with an only digit. And it is parsed correctly for both minutes and seconds with the layout "15:04:05".

@mattn

This comment has been minimized.

Copy link
Member

commented Jan 24, 2019

Ah, I undestand just now. Sorry.

@FiloSottile FiloSottile changed the title time: fails at parsing the hour time: one-digit hour is accepted for 15:04:05 template Jan 24, 2019

@FiloSottile

This comment has been minimized.

Copy link
Member

commented Jan 24, 2019

I'm afraid there is no way to require 24-hour zero-padded hours with a time.Parse template.

/cc @rsc to confirm

@FiloSottile FiloSottile added this to the Unplanned milestone Jan 24, 2019

@FiloSottile

This comment has been minimized.

Copy link
Member

commented Feb 24, 2019

@Virepri You can open a proposal if you want to discuss such a big change, but in general we try not to provide two different ways of doing very similar things in the standard library.

This might be better as an external package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.