-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: provide a complete RFC3339 time format parse function #31113
Comments
The constant I don't see a way to make the current |
Ok, thanks, the error was clear as mud Nevertheless RFC 3339 ABNF does specify that the colon is optional
So timestamps without the colon are conformant to RFC 3339 (and the date command, for example, will omit them by default). And Go won't parse them correctly. |
The documentation says |
While I agree the optional parts of RFC3339 are a major PITA (the W3C was much smarter than the IETF when it defined a single canonical form that only varied depending on the precision of the desired timestamps), those optional parts do exist, and people do write software with their own understanding of the options to include or exclude, and this software outputs timestamps, that Go software can consume later, so the Go parsing part of RFC3339 timestamps at least should accept all the variations defined in the RFC. Because if the parsing is not as permissive as allowed by the spec, individual Go devs will have to reinvent separately timestamp normalising rules, which is not efficient, and what the RFCs are supposed to avoid. And please note I am not talking about all the time RFCs here. Only the most recent, that represents the state of the art in writing interoperable time. Telling projects to upgrade to RFC3339 to be sure their time strings are parsed by Go and other software stacks is perfectly fine. But the RFC3339 support needs to be solid and complete to do that. |
@nim-nim If I understand you correctly, you are asking for something that |
Just as info: The date version 8.28 on my system prints the colon in the offset with --iso-8601=seconds. So the format may have changed between versions. Format with the RFC3339 constant creates a correct RFC3339 time stamp, but Parse is not able to process all valid time stamps according to section 5.6 of the RFC or the ABNF in the appendix. (Mainly because ABNF strings are case-insensitive and so lower-case t and z must be supported.) It also cannot parse all valid ISO8601 extended format time stamps since the time stamp may omit the time zone or use only a time offset providing hours. I agree with @ianlancetaylor that Parse cannot support all variants of RFC3339 and a special parser function for that purpose would be required. |
@ulikunitz @ianlancetaylor Then I suppose a separate function is needed to Go can consume RFC3339-compliant outputs produced by other software :( |
It looks like if you want to parse an RFC3339 time without a colon, you can use:
The broad claim in the initial report, that Go cannot parse RFC3339 times, is clearly wrong. I don't see much to do here. |
But that requires to make every Go software, that consumes things with RFC3339 timestamps, to be aware of all the RFC3339 dialects, or to hope all the other software is works with keeps to a single RFC3339 variant. The second option is unrealistic: different software will output different RFC3339 timestamps, and even the same software can change its RFC3339 options depending on the deployed version. |
What's the recommended pattern for |
@nim-nim I believe you are mistaken about RFC 3339 saying the colon is optional in the timezone. If you look at section 5.6 (https://tools.ietf.org/html/rfc3339#section-5.6), where the ABNF is defined for RFC 3339, it says the colon is mandatory:
I think the section you pulled from was Appendix A (https://tools.ietf.org/html/rfc3339#appendix-A), which describes the ABNF of ISO8601. ISO8601 is more permissive, and does not require colons anywhere.
|
Re-reading the RFC, I think you're right, I was tricked by the double ABNF in the document. Thanks a lot for the verification. |
The W3C profile of the ISO 8601 format, that the IETF formalized in RFC3339, specifies two timezone formats
The two timezone formats are clearly specified both in the W3C and the IETF document.
W3C:
IETF RFC3339 ABNF:
/
meansOR
in ABNF, as is evident from thetime-numoffset
definition, that tells you that ISO 8601 timezone offset can be positive or negative.The golang RFC3339 time format is non conformant, first because it tries to use "Z" in conjunction with timezone offsets (when the meaning of "Z" is that no timezone offset was provided), and second, because it only allows positive offsets, when the W3C ISO 8601 profile and RFC3339 are both very clear offsets can be negative.
As a result, go is unable to parse RFC3339 compliant date times such as the ones outputed by
date --iso-8601=seconds
Please fix the RFC3339 time format in Go or, if the mistake is too old to be easily removed, add a new RFC3339std format that is conformant to the RFC 3339 and ISO 8601, as used by other software in IJSON, XML, etc.
The text was updated successfully, but these errors were encountered: