Git Product home page Git Product logo

Comments (7)

cowtowncoder avatar cowtowncoder commented on August 30, 2024 2

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.

cowtowncoder avatar cowtowncoder commented on August 30, 2024 1

@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.

fabiolimace avatar fabiolimace commented on August 30, 2024 1

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.

pw-lehre avatar pw-lehre commented on August 30, 2024

@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.

yashh avatar yashh commented on August 30, 2024

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.

yashh avatar yashh commented on August 30, 2024

@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.

yashh avatar yashh commented on August 30, 2024

Makes sense. Thank you @fabiolimace

from java-uuid-generator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.