karwa / uniqueid

Random and time-ordered UUID generation in Swift
https://karwa.github.io/uniqueid/main/documentation/uniqueid/
Apache License 2.0
70 stars 10 forks source link

Support for uuidv7? #7

Open rex-remind101 opened 1 year ago

rex-remind101 commented 1 year ago

Thank you for building this library. May support be added for uuidv7?

nthState-Chris commented 7 months ago

I'd also love to see this feature

shaps80 commented 6 months ago

I'd also like this! Also, @nthState-Chris funny finding you here? Hahaha

nthState-Chris commented 6 months ago

Hi @shaps80 great to hear from you! I hope you are well? I actually wrote a small Swift Package to generate UUID V7 strings...it seems to work: https://github.com/nthState/UUIDV7

karwa commented 6 months ago

The main issue is getting a good quality timestamp. IMO the spec is a little bit ambiguous, because the section on UUIDv7 says the timestamp should be:

the number of milliseconds since midnight 1 Jan 1970 UTC, leap seconds excluded.

While other parts of the spec say that the timestamp only needs to be monotonic (BTW, Foundation's Date() initialiser does not make that guarantee), and that

This specification makes no requirement or guarantee about how close the clock value needs to be to the actual time

So it's unclear if we need to care about leap seconds or not. Previously I thought maybe we did, but now I'm leaning towards thinking that we don't (which is easier to implement, thankfully). One of the things on my to-do list is to send some feedback about that.

There are also a number of configuration options. The spec only requires the timestamp have millisecond precision, but there is another field for additional monotonic data, which may be the sub-millisecond portion of the timestamp, a counter, or some combination of the two. I'm debating how much of this to surface in the API; I always like exposing the knobs and dials so professionals can adjust the behaviour for their environment.

I have some other things going on which take priority, but I haven't forgotten about this and hope to get to it in a week or two (more likely two).

shaps80 commented 6 months ago

Yeah I can imagine its a little ambiguous. Appreciate you feeding back. Take your time, I know exactly how you feel haha!