saresend / KSUID

Sortable UIDs in Python
MIT License
95 stars 14 forks source link

The base62 representation of a KSUID shouldn't have less than 27 characters #9

Open ManuelZ opened 2 years ago

ManuelZ commented 2 years ago

From here: “The text representation is always 27 characters, encoded in alphanumeric base62 that will lexicographically sort by timestamp.”

Passing in a timestamp close to the epoch can produce a bytes representation with leading zeros after the epoch has been substracted, which produces KSUIDs with a base62 representation with a length less than 27.

from ksuid import ksuid

EPOCH = int(14e8) # '2014-05-13T16:53:20'

>>> k = ksuid(EPOCH) 
>>> k.toBase62()
'39kHQVbzU2HGjKozI65P4b'
>>> len(k.toBase62())
22

In the Go implementation, a left zero padding is done.

Using the version from master.