ulid
ulid copied to clipboard
Timestamp is in seconds instead of ms for several API calls, also broken on 32 bit systems
Problem Description
Per the ULID spec, the timestamp portion of the ULID is supposed to be the Unix epoch time in ms. The current implementation has several API calls that encode the time in seconds, not milliseconds. time_t
stores the time in seconds, and the following calls use it:
-
void EncodeTime(time_t timestamp, ULID& ulid)
-
void EncodeTimeNow(ULID& ulid)
-
void Encode(time_t timestamp, const std::function<uint8_t()>& rng, ULID& ulid)
-
void EncodeNowRand(ULID& ulid)
-
ULID Create(time_t timestamp, const std::function<uint8_t()>& rng)
-
ULID CreateNowRand()
The exception to this is EncodeTimeSystemClockNow
, which properly encodes ms timestamps.
The second problem around this is that time_t
is only 4 bytes on 32 bit systems (noted in #9), so a call to time_t Time(const ULID& ulid)
on those systems will not work correctly past a certain time.
Potential Fix
I think we should internally fix the API so that it encodes in ms, and ensure that the API only allows encoding the time as ms (using chrony data types can enforce this). We also shouldn't use time_t
as a data type when we need 8 bytes of space to do operations.