-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: time: also support 31 as day in time layout #45645
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
Comments
CC @robpike |
While admitting that the original canonical date could have been better chosen, with an eye on international formats rather than the output of Unix |
Based on the discussion above, this proposal seems like a likely decline. |
31 doesn’t support leading zeros and it screws up the day of the week. I think it’s a non-starter. |
No change in consensus, so declined. |
I propose adding
31
as an alternative to the day in the time layout string. There have been proposals/issues before discussing the go time layout, but I haven't seen this before.The main rationale is that the current January 2nd format is not obvious, as
01
and02
are easy to mix up. This is even more the case outside of the US, where it's common to format dates as YYYY-MM-DD or DD-MM-YYYY.Consider the following:
I think the latter (
b
) produces more readable code because there is no ambiguity in what the output will be. It is immediately obvious to the reader which one is the month and which one is the day.This is even more clear when the year is "disconnected" from the day/month:
The same of course applies to parsing dates:
I'm not proposing to change the existing format, just to also support
31
for formatting/parsing the day.This does add another way of doing the same thing, which could be seen as a negative. However, I think it does improve readability (especially outside the US), so I hope this proposal can be considered.
Why
31
While any number after
12
(except15
because of 24h hour) would work, I believe31
is an "even" and recognizable number when it comes to calendar dates. January happens to have 31 days so the new reference date is also a valid real-world date.Another option would be
20
, which is a "reverse" of the current zero prefixed day02
.20
has the downside that it can be confused with 8pm in a 24h clock.Padding
Defining padding is not possible here. I think it should format with a leading zeros because 31 has two digits and based on my anecdotal evidence, it's more common to have a leading zero. If formatting a date without leading zero is important, the existing
2
or_2
can still be used.Backwards compatibility
As far as I can tell, this change is backward compatible. The only case where I can think of this causing different behavior from before is if
31
is used in the layout string, but this would have caused unexpected results as3
and1
would already be replaced with the 12h hour and month.Implementation
Currently
3
is parsed as the 12h clock hour. The change would continue parsing the date to see if it is followed by a1
. Believe this would just mean adding the following here:Similar proposals:
The text was updated successfully, but these errors were encountered: