-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: time: support Colon for fractional seconds #36145
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
This is not an issue. Please review the documentation for package time:
For your example, the format string must be Here is your example corrected: https://play.golang.org/p/E46bFklY7L3 |
I'm sorry but I have to disagree. I reviewed the documentation thoroughly before writing the original issue, and I am well aware that the problem does not occur if a period is used in place of a colon. That was the whole point of the report I filed. The generated file I am processing uses a colon instead of a period. Which is non-standard, I completely agree. But, that's kind of my point. Non-standard things happen "in the wild", and the library needs to be able to handle them. Yes, I can work around it by doing a search and replace on the colon in the string. That's what I'm doing for now. But the whole point of a format string, is to... specify the format of the string you want to parse. It's seems we've missed the mark if we have cases like that that it is impossible to format for. Please, I would ask you, give the issue some more consideration before dropping it again. I'm not expecting this will change tomorrow or anything like that, but isn't it better in the long term if the format strings are able to cover a wider variety of cases ? This general theme seems to be a recurring issue, to wit: Couldn't some consideration be given to this? Alternatively, maybe this is a plus point for the priority of localization support |
It seems like you want to file a proposal, rather than an issue. And from what I understand, your proposal is very similar to #6189. I'd suggest that you can subscribe to that issue for updates. Or if you feel the colon as a separator deserves its own proposal, please feel free to go ahead and file one. |
All the details are here already—reopened and converted to proposal. |
Maybe you can try this package: https://github.com/tengattack/jodatime ;) for arbitrary format |
Unfortunately, many things happen in the wild, and it is not a goal to handle all of them. That would lead to enormous libraries that are hard to learn to use. |
This proposal has been added to the active column of the proposals project |
Thank you for considering this further. I very much agree with exactly the sentiment expressed by @trbroyles1 above.
I believe there is a very specific ask here, which is to make one specific separator configurable. It could likely be limited to a very small set of possible values, perhaps While it is trivial to write a string replacement, it is a major performance hit when attempting to process millions of timestamps per second, for example. Admittedly, it should be difficult to justify a general performance hit for all users of |
If timestamp processing is a bottleneck, I would strongly encourage you to write a custom parser rather than using |
My primary use case is distributed log processing, which involves consuming a wide variety of timestamp layouts. Performance-wise, Details of my use case aside, I mostly just wanted to draw focus to the fact that this proposal is a narrowly defined ask, and that is aligned with what I understand to be the purpose of |
We still can't do everything. To be worth making a special case here we'd need to know this was a very common thing to run into. A priori it sounds like it's not. But do you perhaps know what is generating these odd times? Is there some commonly-used spec we are unaware of? |
Log4J has a default timestamp format that uses According to Wikipedia, ISO_8601 states that a comma is acceptable, even preferred. Presumably that may be why Log4J chose this default. I have personally only run into the need for a comma as an alternate separator, but as an additional data point, here is a list of timestamp formats recognized by Sumo Logic, which appears to include at least one other separator. |
Comma seems plausible, because of course many countries use decimal comma. But that is not this proposal. One thing to consider is that if we recognize other characters as introducing a fractional number of seconds, it will be possible to write formats whose behavior will change unexpectedly. For example, |
In the absence of some kind of widely-used standard that uses : for a decimal point in this context, it seems like we should not add the complexity here. Comma is a separate issue (#43823). |
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
Change https://golang.org/cl/300996 mentions this issue: |
Accepts comma "," as a separator for fractional seconds hence we now accept: * 2006-01-02 15:04:05,999999999 -0700 MST * Mon Jan _2 15:04:05,120007 2006 * Mon Jan 2 15:04:05,120007 2006 This change follows the recommendations of ISO 8601 per https://en.wikipedia.org/wiki/ISO_8601#cite_note-26 which states ISO 8601:2004(E), ISO, 2004-12-01, "4.2.2.4 ... the decimal fraction shall be divided from the integer part by the decimal sign specified in ISO 31-0, i.e. the comma [,] or full stop [.]. Of these, the comma is the preferred sign." Unfortunately, I couldn't directly access the ISO 8601 document because suddenly it is behind a paywall on the ISO website, charging CHF 158 (USD 179) for 38 pages :-( However, this follows publicly available cited literature, as well as the recommendations from the proposal approval. Fixes #6189 Updates #27746 Updates #26002 Updates #36145 Updates #43813 Fixes #43823 Change-Id: Ibe96064e8ee27c239be78c880fa561a1a41e190c Reviewed-on: https://go-review.googlesource.com/c/go/+/300996 Trust: Emmanuel Odeke <emmanuel@orijtech.com> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Rob Pike <r@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
I get that this issue is closed and sorry in advance for the necro but searching led me here, and I wanted to add a data point since the only data point that appears in this thread is log4j. My use case is that Unreal Engine 4 formats log timestamps in a custom way e.g. The reason this is problematic is that I'm piping logs from a UE4 game server to a SaaS called Honeycomb (written in go, and it more or less passes timestamps through to Trying to make this work isn't as simple as modifying some of my application code which seems to be the workaround folks have settled on. To solve this, I'd either have to open a PR to Honeycomb, modify Unreal Engine's source, or create an entirely new log sink in my UE game code. So in my mind this issue represents a developer experience issue (not a loc issue) since all of those approaches are much higher effort than adding more flexible time parsing support. I'm not intending to re-open this, I'll just say that as a person that's learning Go to investigate this issue, it feels like an odd choice to not allow decoupling of the seconds from the milliseconds in a time format string. For context, I'm coming from the .net world where you would use the string |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, I can reproduce it on the playground
What operating system and processor architecture are you using (
go env
)?GOOS=windows
GOARCH=amd64
GOHOSTARCH=amd64
go env
OutputWhat did you do?
Attempt to parse a date/time string containing milliseconds preceded by a colon. Example:
https://play.golang.org/p/eY-B7yU7cbT
What did you expect to see?
Time is 02/12/2019 15:45:48:746
What did you see instead?
parsing time "02/12/2019 15:45:48:746" as "02/01/2006 15:04:05:000": cannot parse "746" as ":000"
The text was updated successfully, but these errors were encountered: