-
Notifications
You must be signed in to change notification settings - Fork 18k
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: RFC3339Nano does not guarantee natural ordering #19635
Comments
We can't change We could introduce |
I'm using my own constant defined right now, yes. Perhaps it's not worth the change, i just feel as though this should be raised or considered as we're declaring RFC3339 but not fully implementing it. My biggest issue with the new constant name is just that it doesn't look right 😹 if anyone has a better name/solution (other than defining your own) i welcome it! i also think it's worth noting that https://golang.org/doc/go1compat mentions that the team reserves the right to fix bugs, and i would consider this a bug |
We could also just document the difference and/or add an example. |
CL https://golang.org/cl/47090 mentions this issue. |
When using time as key in time-series databases such as BoltDB, the key is internally sorted by DB. This approach allows very fast search, however, a key has to be sortable. If you come to accept this arguments, I also propose RFC3339MilliNatural, since it is sufficient in most real world cases (especially in IoT world) and on few million entries it saves a lot. |
@ljubomirb This issue was closed months ago. To change that decision I think requires a practical argument, not a theoretical one. For example, show us several unrelated packages that are working around this problem. |
I understand that is is closed, and that you gave it a thought before, but I ask you to consider it maybe one more time.
You may argue that it's all just a simple matter of inserting format string, so one can simply introduce his own format const like As for my proposal of adding Millis (natural), I have nothing but theoretical argument: most IoT devices work in sub 40MHz clock range. When they capture, process and at the end send event of interest to database backend (often using speeds like 9600bps), then using nano precision during logging is just wrong. If, on the other hand, device is capable to internally capture event related in time difference to previous one (like GPIO rising edge times), then Nano will be used anyway. P.S. another problem one will encounter is that if you have variable number of digits of unpredictable length, then sending the same timestamp to different databases will result in different times being saved, due to the way trim or round is performed in different versions of same databases, and thus you cannot rely to query DB by exact date as noted here for MySQL
If you, however, do know the length of your time string, than it's easier to approach this problem. |
Alternatively you can use |
Hi!
When the time.Time used in Format(time.RFC3339Nano) is rounded to the nearest second (or anything lower than nanosecond), any trailing 0s are not formatted due to the formatting string.
RFC3339Nano should format to a natural/string sortable value. This is mentioned in section 5.1 of RFC3339 https://www.ietf.org/rfc/rfc3339.txt
I propose that time.RFC3339Nano is updated to the following formatting string:
"2006-01-02T15:04:05.000000000Z07:00"
or that a time.RFC3339NanoNatural (or similar) constant is declared
thanks for your time!
What version of Go are you using (
go version
)?go version go1.8 darwin/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
I formatted two time.Time values using RFC3339Nano
https://play.golang.org/p/qY81JM6Np8
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: