-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
Comments
Please try this instead https://play.golang.org/p/k7kmlXt15zF |
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". |
Ah, I undestand just now. Sorry. |
I'm afraid there is no way to require 24-hour zero-padded hours with a time.Parse template. /cc @rsc to confirm |
@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. |
Change https://go.dev/cl/425044 mentions this issue: |
Seems a bit much to maintain and/or import an external package for such a minor feature? Anyway, this is what I came up with for the time being:
|
What version of Go are you using (
go version
)?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.
The text was updated successfully, but these errors were encountered: