We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f4f56de commit 38d46e3Copy full SHA for 38d46e3
1 file changed
src/uuid6/__init__.py
@@ -82,14 +82,9 @@ def uuid1_to_uuid6(uuid1: uuid.UUID) -> UUID:
82
r"""Generate a UUID version 6 object from a UUID version 1 object."""
83
if uuid1.version != 1:
84
raise ValueError("given UUID's version number must be 1")
85
- timestamp = uuid1.time
86
- time_high_and_time_mid = timestamp >> 12
87
- time_low_and_version = timestamp & 0x0FFF
88
- uuid_int = time_high_and_time_mid << 80
89
- uuid_int |= time_low_and_version << 64
90
- uuid_int |= uuid1.clock_seq << 48
91
- uuid_int |= uuid1.node
92
- return UUID(int=uuid_int, version=6, is_safe=uuid1.is_safe)
+ h = uuid1.hex
+ h = h[13:16] + h[8:12] + h[0:5] + "6" + h[5:8] + h[16:]
+ return UUID(hex=h, is_safe=uuid1.is_safe)
93
94
95
_last_v6_timestamp = None
0 commit comments