Skip to content

Commit b34dd58

Browse files
authored
bpo-41710: Document _PyTime_t API in pytime.h (GH-28647)
1 parent 37b8294 commit b34dd58

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

Include/cpython/pytime.h

+41
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,44 @@
1+
// The _PyTime_t API is written to use timestamp and timeout values stored in
2+
// various formats and to read clocks.
3+
//
4+
// The _PyTime_t type is an integer to support directly common arithmetic
5+
// operations like t1 + t2.
6+
//
7+
// The _PyTime_t API supports a resolution of 1 nanosecond. The _PyTime_t type
8+
// is signed to support negative timestamps. The supported range is around
9+
// [-292.3 years; +292.3 years]. Using the Unix epoch (January 1st, 1970), the
10+
// supported date range is around [1677-09-21; 2262-04-11].
11+
//
12+
// Formats:
13+
//
14+
// * seconds
15+
// * seconds as a floating pointer number (C double)
16+
// * milliseconds (10^-3 seconds)
17+
// * microseconds (10^-6 seconds)
18+
// * 100 nanoseconds (10^-7 seconds)
19+
// * nanoseconds (10^-9 seconds)
20+
// * timeval structure, 1 microsecond resolution (10^-6 seconds)
21+
// * timespec structure, 1 nanosecond resolution (10^-9 seconds)
22+
//
23+
// Integer overflows are detected and raise OverflowError. Conversion to a
24+
// resolution worse than 1 nanosecond is rounded correctly with the requested
25+
// rounding mode. There are 4 rounding modes: floor (towards -inf), ceiling
26+
// (towards +inf), half even and up (away from zero).
27+
//
28+
// Some functions clamp the result in the range [_PyTime_MIN; _PyTime_MAX], so
29+
// the caller doesn't have to handle errors and doesn't need to hold the GIL.
30+
//
31+
// Clocks:
32+
//
33+
// * System clock
34+
// * Monotonic clock
35+
// * Performance counter
36+
//
37+
// Operations like (t * k / q) with integers are implemented in a way to reduce
38+
// the risk of integer overflow. Such operation is used to convert a clock
39+
// value expressed in ticks with a frequency to _PyTime_t, like
40+
// QueryPerformanceCounter() with QueryPerformanceFrequency().
41+
142
#ifndef Py_LIMITED_API
243
#ifndef Py_PYTIME_H
344
#define Py_PYTIME_H

0 commit comments

Comments
 (0)