You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On the lastest episode of Cup o' Go, we mentioned the (now declined) proposal to add "1136214245" as layout string for unix timestamp. This sparked a discussion of the deep dislike people have for the current time.Parse formats on the #cup-o-go Slack Channel, including the following comments. Keep in mind that the channel is a lot less formal than the proposal process is, so these quotes should be taken lightly:
Add a "Layout" type to the time.Parse API, similar to how Rust does it
This is a bit cumbersome - but honestly, I've never been able to use time.Parse without having to double-check which parameter is the layout and which parameter is the input. So something like:
myCoolLayout, layoutErr:=time.NewLayout("%d/%m/%y %H:%M:%S.%f") // Error if format is bad, e.g. includes unknown letters?iflayoutErr!=nil {
// Handle it however you want, I assume this is almost always a panic
}
myTime, timeErr:=time.Parse(myCoolLayout, ""31/01/2223:59:59.999999"")
The text was updated successfully, but these errors were encountered:
@seankhliao can the long list of people who already suggested this, and the feedback, warrant a re opening of this issue?
Bare minimum, if the x-in-std lib argument is a winner, can we update the docs for time.Parse to let people know about the strftime stuff that lives outside the stdlib?
Edit: oops, answered from my Corp account, but I'm the OP 😅
Not only that, but looking for non-stdlib-implementations, looks like there are many, and non are "dominating". So the same case that was made for keeping YAML out of the STDLIB (see #61023) by @rsc:
On top of that, @niemeyer has done an excellent job writing gopkg.in/yaml.v3, which as the top comment points out is the most widely used YAML package in the Go ecosystem. For that I am incredibly grateful, and I think we should continue to encourage use of that package.
To allow us to make progress, once we've made a decision, we will generally not relitigate without significant new information.
While popularity is a factor to consider, the general lack of popularity of third party packages (relative to recent additions such as http mux patterns or structured logging or non-additions such as yaml) would indicate that it isn't there.
Go generally aims to have a single way to do things, at least within the standard library, and we have one that works for time. While this doesn't preclude the existence of third party packages like strftime, it is a reason for it not to refer to arbitrary outside resources.
Proposal Details
Previous work and context
This is a continuation of two previous discussions (there might be more, but I haven't found them):
time.Parse
formats on the #cup-o-go Slack Channel, including the following comments. Keep in mind that the channel is a lot less formal than the proposal process is, so these quotes should be taken lightly:Comparison to other languages
I propose we support a layout that's much easier to read and understand, similar to other time format options. Existing references include:
datetime
module format codesAll these examples are widely used and, very notably, don't work the same way as we do it in Go.
What do I think we should do in Go, then?
I suggest two options to consider:
Keep the current API and add support for layouts with chars
Which will look like this (I randomly picked the Python letters/format, but we could pick another layout table if we want).
Add a "Layout" type to the time.Parse API, similar to how Rust does it
This is a bit cumbersome - but honestly, I've never been able to use
time.Parse
without having to double-check which parameter is the layout and which parameter is the input. So something like:The text was updated successfully, but these errors were encountered: