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.
I use shortened
ulid
s where I truncate the randomness part of theulid
(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. CandecodeTime()
be modified to allow both a 26 char and a 10 charulid
, or is there something else I am missing? I know I can generate my own random portion, concatenate it with the truncatedulid
, and then calldecodeTime()
, but that seems circuitous.