-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: add DateTime, DateOnly, TimeOnly format constants #52746
Comments
Perhaps |
RFC3339 provides the extended ISO date and time format - using Perhaps something like |
It sounds like maybe
This would align with RFC3339 and RFC3339Nano and add the date-only form. Thoughts? /cc @robpike |
Also, thanks for the great data @dsnet |
The ISO names are fine, but I see advantages to also having the nicer names like TimeOnly and DateOnly as aliases. I remain a fan of time.Kitchen, which is underused. |
I'm used to reading specs, but I'm overwhelmed by ISO 8601 🤯. On Wikipedia, it says:
If true, it seems that (Side comment: Thank you Go language for having a simple and concise language specification). |
OK, it sounds like we can't call these ISO8601, and maybe that's not specific enough either. But what should we call them instead?
But also the 9999 comes from the RFC3339 definition; Stamp has 0s instead, meaning that the digits are always there:
I don't know which of these we'd want either. Maybe we are biting off too much and should just do:
and stop there? |
The |
This proposal has been added to the active column of the proposals project |
The proposed formats are defined in the |
My preference is for a human-friendly name without yet another number sequence. |
What about |
|
Given @dsnet's data, let's consider doing:
Does anyone object to these? |
Would it be possible to tell how users name these constants?
Looking at the top two popular formats I think users mean to use "reduced" RFC3339 format. It is not something else because only RFC3339 format puts fields in descending order making string representations sortable. The field separator is also the same
As per #52746 (comment) these formats are somewhat defined in the RFC section named "Internet Date/Time Format". It also has a note about space separator used in these formats:
Usage in situ: time.Parse(time.DateTime, s)
time.Parse(time.DateOnly, s)
time.Parse(time.TimeOnly, s) vs time.Parse(time.RFC3339DateTime, s)
time.Parse(time.RFC3339Date, s)
time.Parse(time.RFC3339Time, s) vs time.Parse(time.InternetDateTime, s)
time.Parse(time.InternetDate, s)
time.Parse(time.InternetTime, s) |
I think these were taken directly from the call sites. They name them like |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
Change https://go.dev/cl/412495 mentions this issue: |
Add named constants for the 3rd, 4th, and 13th most popular formats. Fixes golang#52746 Change-Id: I7ce92e44dcae18c089124f1d6f5bc2d6359d436c Reviewed-on: https://go-review.googlesource.com/c/go/+/412495 Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Joseph Tsai <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Joseph Tsai <[email protected]>
Change https://go.dev/cl/433277 mentions this issue: |
Use the newly defined time.Datetime constant instead of a string literal. Updates #52746 Change-Id: I2722415ecc67fd2adfdab2eaba3298774032bff3 GitHub-Last-Rev: 65d3aa9 GitHub-Pull-Request: #55833 Reviewed-on: https://go-review.googlesource.com/c/go/+/433277 Run-TryBot: Joseph Tsai <[email protected]> Auto-Submit: Joseph Tsai <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Joseph Tsai <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Bryan Mills <[email protected]>
This comment was marked as off-topic.
This comment was marked as off-topic.
@gouguoyin this proposal is accepted and implemented, and you don't seem to be proposing anything for the time package, so that seems off-topic to me. |
* Upgrade Go version from 1.19 to 1.20 * Utilize 'time.Dateonly' for enhanced formatting, see: golang/go#52746
* Upgrade Go version from 1.19 to 1.20 * Utilize 'time.Dateonly' for enhanced formatting, see: golang/go#52746
I propose the declaration of the following format constants to the
time
package:Analyzing all Go code on the module proxy (as of 2022-04-01), here's a table of all common time formats sorted in popularity order:
time.RFC3339
time.RFC3339Nano
"2006-01-02 15:04:05"
"2006-01-02"
time.RFC1123
time.RFC1123Z
time.UnixDate
time.ANSIC
"20060102"
time.RFC822
time.Kitchen
"20060102150405"
"15:04:05"
time.RFC850
time.Stamp
"2006-01-02T15:04:05Z"
"2006-01-02T15:04:05"
"2006"
"2006/01/02 15:04:05"
time.StampMilli
time.RFC822Z
time.RubyDate
"15:04"
"2006-01-02 15:04:05.000"
"2006010215"
"15:04:05.000"
"2006-01-02 15:04"
"2006/01/02 - 15:04:05"
"2006/01/02"
time.StampNano
time.StampMicro
As can be seen,
"2006-01-02 15:04:05"
and"2006-01-02"
are the 3rd and 4th most popular format constants. They are more popular than most of the othertime
format constants that did get a named declaration.Given their popularity, I propose declaring:
Other constant name suggestions welcome.
The text was updated successfully, but these errors were encountered: