ulid / javascript

Universally Unique Lexicographically Sortable Identifier

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generate time from shortened ulid?

beevor opened this issue · comments

I use shortened ulids where I truncate the randomness part of the ulid (last 16 characters) and use the timestamp portion (first ten characters) as keys in a database. The reason being that the timestamp alone offers sufficient resolution, with the randomness increasing the storage size with no benefit. Now, if I want to recover the time from the timestamp portion, decodeTime() requires a full length (26 char) ulid, though, strictly speaking, only the first 10 chars encode time information. Can decodeTime() be modified to allow both a 26 char and a 10 char ulid, or is there something else I am missing? I know I can generate my own random portion, concatenate it with the truncated ulid, and then call decodeTime(), but that seems circuitous.