diff --git a/ulid/__init__.py b/ulid/__init__.py index 1ff7164..0eaeb33 100644 --- a/ulid/__init__.py +++ b/ulid/__init__.py @@ -70,7 +70,9 @@ class ULID: def __init__(self, value: bytes | None = None) -> None: if value is not None and len(value) != constants.BYTES_LEN: raise ValueError("ULID has to be exactly 16 bytes long.") - self.bytes: bytes = value or ULID.from_timestamp(time.time()).bytes + self.bytes: bytes = ( + value or ULID.from_timestamp(time.time_ns() // constants.NANOSECS_IN_MILLISECS).bytes + ) @classmethod @validate_type(datetime) diff --git a/ulid/constants.py b/ulid/constants.py index a0a1995..bc182c6 100644 --- a/ulid/constants.py +++ b/ulid/constants.py @@ -1,4 +1,5 @@ MILLISECS_IN_SECS = 1000 +NANOSECS_IN_MILLISECS = 1000000 TIMESTAMP_LEN = 6 RANDOMNESS_LEN = 10