Skip to content
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

How to extract time from an uuid v1? #297

Closed
aalexgabi opened this issue Oct 17, 2018 · 5 comments
Closed

How to extract time from an uuid v1? #297

aalexgabi opened this issue Oct 17, 2018 · 5 comments

Comments

@aalexgabi
Copy link

I found this: krassif@a9aac0e
From here: https://stackoverflow.com/questions/17571100/how-to-extract-timestamp-from-uuid-v1-timeuuid-using-javascript

But since node-uuid (the npm module) is deprecated: https://www.npmjs.com/package/node-uuid what can I use?

It looks to me that this feature should be included in this library.

@broofa
Copy link
Member

broofa commented Oct 17, 2018

https://www.npmjs.com/package/uuid-time works. Just be aware that the value it returns (Unix epoch, +/- 1 msec) is imprecise. (v1 uuids are precise to +/- 0.01 μsec)

See also #49 (comment)

@broofa broofa closed this as completed Oct 17, 2018
@aalexgabi
Copy link
Author

Thanks!

@croraf
Copy link

croraf commented Jan 23, 2022

Can this be included in this library? (would offer TS support also)

@ctavan
Copy link
Member

ctavan commented Jan 23, 2022

Given there has not been a single request for this feature in the past 3 years and given there’s a dedicated npm module for this use case, I think it’s very unlikely that we‘ll support this feature in this library.

@broofa
Copy link
Member

broofa commented Jan 23, 2022

~10-15 people have shown interest in this feature in the last decade (including comments on #49). The uuid-time module that spun out of that gets ~900 downloads/week, compared to uuid's current traffic of 67M/week.

In addition to the lack of demand, there's also the matter of deciding what the "right" API should be. I'm not convinced there's good solution here, due to the [arguably] poor choice of epoch used in RFC4122 (gregorian epoch, 100-nsec units) that makes using JS Number objects for timestamps problematic. uuid-time returns a JS timestamp value (unix epoch, msec units), but drops out of necessity drops the sub-msec info. uuid uses msec and nsec values internally and (regrettably?) exposes those in the API. But those are ad-hoc and pretty arbitrary in how they're defined. Really, the best datatype for is probably BigInt, but BigInts are cumbersome to work with. (E.g. new Date(1234n) throws) and, I suspect, probably aren't what most people need.

Oh, and there's a new proposal in the works - https://github.com/uuid6/uuid6-ietf-draft - that adds another epoch to the mix. (Unix, 1-nanosecond units).

I guess the TL;DR: is that I [still] don't see a solution popular and "right" enough to warrant taking this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants