-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
Add UUIDUtil.extractTimestamp()
for extracting 64-bit timestamp for all timestamp-based versions
#81
Comments
I don't think this belongs in generator, however, there is class Calculation for version 1 is bit more complicated due to odd "100 nanoseconds as unit" part but technically doable. I'd be happy to help with a PR if anyone is interested in adding this. |
Thank you for the quick reply.
I would expect that for version 1, one could just use java.util.UUID#timestamp() . As for going from "100s of nanos since gregorian epoch" to "millis since unix epoch", how about this:
|
If I read Javadocs for
it does NOT give value comparable to This is fine, of course, Then there are questions of what to do with ones that have no timestamp; either return |
Hi, thank you for taking the time. Right, UUID.timestamp() shuffles the MSB of UUIDv1 and returns the number of "100-nanosecond units since midnight, October 15, 1582 UTC." (lets call that gregorian epoch) So my original ask was for the equivalent of UUID.timestamp() for UUIDv6. That's why I used the term timestamp. But ultimately I want the milliseconds since unix epoch, for which it seems the conversion is:
I don't really need the "100-nanosecond units since gregorian epoch", I only asked for it because UUIDv1 and UUIDv6 have different conversions from MSB to "100-nanosecond units since gregorian epoch", and then the same conversion from that to "millis since unix epoch".
my 2c: UUID.timestamp() throws UnsupportedOperationException. If only for this reason I would do the same. |
Sounds good. If anyone has time and interest to work on this, I'm happy to help getting it done. |
UUIDUtil.extractTimestamp()
for extracting 64-bit timestamp for all timestamp-based versions
java.util.UUID#timestamp() only works for version 1 UUIDs.
It would be nice to have similar functionality for version 6 UUIDs.
E.g. a static method in TimeBasedReorderedGenerator, something along the lines of
Better yet, a static method in UUIDUtil that returns the number of millis since unix epoch for versions 1, 6 and 7 UUIDs.
thank you very much
Gabriel
The text was updated successfully, but these errors were encountered: