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

Timestamp #13

Closed
cnkdynamics opened this issue Oct 9, 2014 · 6 comments
Closed

Timestamp #13

cnkdynamics opened this issue Oct 9, 2014 · 6 comments

Comments

@cnkdynamics
Copy link

Can I get the timestamp from the generated id?

@ericelliott
Copy link
Collaborator

Yes, but I don't recommend it. You should create a separate timestamp instead.

See https://github.com/ericelliott/cuid#broken-down

and from the same README...

"The cuid specification should not be considered an API contract. Code that relies on the groupings as laid out here should be considered brittle and not be used in production."

@cnkdynamics
Copy link
Author

Thanks.

On Fri, Oct 10, 2014 at 9:00 PM, Eric Elliott notifications@github.com
wrote:

Yes, but I don't recommend it. You should create a separate timestamp
instead.

See https://github.com/ericelliott/cuid#broken-down

and from the same README...

"The cuid specification should not be considered an API contract. Code
that relies on the groupings as laid out here should be considered brittle
and not be used in production."


Reply to this email directly or view it on GitHub
#13 (comment).

Felipe Lorenzo VI

@Cicko
Copy link

Cicko commented Apr 2, 2024

@ericelliott How can I find the algorithm to get the date from the cuid?

From what I see from the README it says that the first 8 characters after the letter 'c' is the timestamp, but how can I convert it to an actual date?

And why you don't recommend it?

Thanks in advance

@ericelliott
Copy link
Collaborator

As explained above, and in the documentation, you don't. If you need to know the time something was created, record a separate timestamp. Ids should only be used as ids, and the cuid spec was not designed for data extraction. Groupings do not have guaranteed lengths.

@ericelliott
Copy link
Collaborator

The security risk associated with extracting metadata from ids is the reason CUID is deprecated and we now prefer CUID2.

@Cicko
Copy link

Cicko commented Apr 3, 2024

@ericelliott Thank you for your answer.

I asked because in our project we just added a field createdAt in our PostgresSQL recently and we set a default value of '1999-12-31 23:59:59.000' so all older tuples in the DB have this value which is unrealistic and I thought by running another migration and decode the id (which is a cuid) could at least populate a correct createdAt value.

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

2 participants