Comments (7)
Good point: timestamps used are indeed different: original UUID versions (v1 - v4) used higher-granularity ones with 100 ns resolution -- these take lots of space (bits). So v7 trades in smaller size for lower granularity.
from java-uuid-generator.
@yashh FWTW, timezone is not relevant; timestamps do not use or have it (generally it's offset from UTC but no timezone info is included).
from java-uuid-generator.
Some implementations are based on old drafts. That's why https://github.com/stevesimmons/uuid7 is different.
In 2021, UUIDv7 reserved 36 bits for seconds (not milliseconds). To extract the timestamp from this particular implementation, you must extract the initial 36 bits.
UUID uuid = UUID.fromString("061cb26a-54b8-7a52-8000-2124e7041024");
long seconds = uuid.getMostSignificantBits() >>> (Long.SIZE - 36);
Instant instant = Instant.ofEpochSecond(seconds);
System.out.println(instant); // prints 2021-12-28T15:00:53Z
from java-uuid-generator.
@yashh It is generally discouraged to do so, e.g. https://datatracker.ietf.org/doc/html/draft-ietf-uuidrev-rfc4122bis#name-opacity
That being said, since the time stamp is defined as 48 bits (cf. https://datatracker.ietf.org/doc/html/draft-ietf-uuidrev-rfc4122bis#name-uuid-version-7), you can extract it with:
long timestamp = uuid.getMostSignificantBits() >>> (Long.SIZE - 48);
from java-uuid-generator.
Thank you @pw-lehre . My only motive was to make sure the library is taking the current timestamp and which timezone. Thank you for pointer.
from java-uuid-generator.
@cowtowncoder Yup. I was using https://github.com/stevesimmons/uuid7 library to verify that timestamp and all checks out. But there is something wrong with that library. The timestamp its generating is around year 1983. I tried https://github.com/oittaa/uuid6-python and everything checks out.
from java-uuid-generator.
Makes sense. Thank you @fabiolimace
from java-uuid-generator.
Related Issues (20)
- `UUIDUtil.extractTimestamp()` is broken for versions 1 and 6 HOT 1
- Update About section of the repo HOT 1
- Release 5.1.0 wanted HOT 1
- Add constants for "Nil UUID", "Max UUID" (from draft "new UUID" spec) in `UUIDUtil`
- H HOT 1
- Microsecond / nanosecond part of time based uuid set even if UUIDClock is millisecond precision HOT 2
- Release with UUID v7 support? HOT 5
- Enable "Reproducible Build"
- Ensure correct distinction between variant and version in documentation HOT 2
- UUID version 7 implementation sorting incorrect? HOT 11
- Type 1 UUID getTimestamp() synchronization leads to performance bottleneck HOT 5
- Add `Generators.defaultTimeBasedGenerator()` to use "default" interface address for time/based UUIDs
- TimeBasedEpochGenerator (UUIDv7) can't be provided a `UUIDClock` HOT 5
- Confusing comment wrt synchronization HOT 3
- Add `UUIDUtil.extractTimestamp()` for extracting 64-bit timestamp for all timestamp-based versions HOT 5
- Guidance on how to handle IllegalStateException from TimeBasedEpochGenerator HOT 5
- Add code coverage reporting HOT 1
- Need more testing to increase code coverage (at least to 50%) HOT 7
- What is a valid UUID HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java-uuid-generator.