Skip to content

Commit fd1b98d

Browse files
picnixzhugovk
andauthored
gh-130843: add UUIDv7 timestamp recipes (#132154)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
1 parent ce72457 commit fd1b98d

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Doc/library/uuid.rst

+13-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ which relays any information about the UUID's safety, using this enumeration:
121121
- The last 48 bits of the UUID. Only relevant to version 1.
122122

123123
* - .. attribute:: UUID.time
124-
- The 60-bit timestamp for version 1 and 6,
125-
or the 48-bit timestamp for version 7.
124+
- The 60-bit timestamp as a count of 100-nanosecond intervals since
125+
Gregorian epoch (1582-10-15 00:00:00) for versions 1 and 6, or the
126+
48-bit timestamp in milliseconds since Unix epoch (1970-01-01 00:00:00)
127+
for version 7.
126128

127129
* - .. attribute:: UUID.clock_seq
128130
- The 14-bit sequence number. Only relevant to versions 1 and 6.
@@ -434,6 +436,15 @@ Here are some examples of typical usage of the :mod:`uuid` module::
434436
>>> uuid.MAX
435437
UUID('ffffffff-ffff-ffff-ffff-ffffffffffff')
436438

439+
>>> # get UUIDv7 creation (local) time as a timestamp in milliseconds
440+
>>> u = uuid.uuid7()
441+
>>> u.time # doctest: +SKIP
442+
1743936859822
443+
>>> # get UUIDv7 creation (local) time as a datetime object
444+
>>> import datetime as dt
445+
>>> dt.datetime.fromtimestamp(u.time / 1000) # doctest: +SKIP
446+
datetime.datetime(...)
447+
437448

438449
.. _uuid-cli-example:
439450

0 commit comments

Comments
 (0)