Skip to content
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

proposal: time: Add RFC3339Milli and/or RFC3339Micro convenience constants to standard library #36472

Open
mattwelke opened this issue Jan 9, 2020 · 0 comments

Comments

@mattwelke
Copy link

@mattwelke mattwelke commented Jan 9, 2020

When I searched for this issue first, I found an issue in this repo and followed a chain of issues until I found this original issue where this was already suggested: #13291. Because that issue is locked, I can't add suggestion there. That's why I'm opening a new issue.

I'd like to request again that this be done. I understand the original feelings of the maintainers, where they hesitated to add more to a standard library without justification. Here's a use case I encountered today that I believe justifies this change. We use BigQuery on GCP, where we often use TIMESTAMP columns. They support up to microsecond precision, but no more precision than this. Some mechanisms for parsing values from strings into these columns will fail if the string has too much precision:

image


The solution for this particular use case is to provide a string with no more than microsecond precision:

image


The next level of precision the time package convenience constants provide is second precision with the time.RFC3339 constant. Unfortunately for us, this doesn't work for our use case, where we need at least millisecond precision in order to meaningfully use the data stored in those TIMESTAMP columns. I had to add code to our own code base that our developers will have to remember exists and that they must use instead of first looking at the standard library:

const (
	timeFormatRFC3339Micro = "2006-01-02T15:04:05.999999Z07:00"
)

I understand that as developers, it's our job to validate our data properly before storing it, but it would still be very useful to have an easy way, built into the language, for Go developers to parse standard time strings with more than second precision if nanosecond precision is too much for their use case.

@toothrot toothrot changed the title Suggestion: Add RFC3339Milli and/or RFC3339Micro convenience constants to standard library proposal: time: Add RFC3339Milli and/or RFC3339Micro convenience constants to standard library Jan 9, 2020
@gopherbot gopherbot added this to the Proposal milestone Jan 9, 2020
@gopherbot gopherbot added the Proposal label Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.