Skip to content

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

@mattwelke

Description

@mattwelke

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions