cpython: 65ac8e587bb0 (original) (raw)

--- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -21,6 +21,8 @@ SIZEOF_INT = sysconfig.get_config_var('S TIME_MAXYEAR = (1 << 8 * SIZEOF_INT - 1) - 1 TIME_MINYEAR = -TIME_MAXYEAR - 1 +US_TO_NS = 10 ** 3 +MS_TO_NS = 10 ** 6 SEC_TO_NS = 10 ** 9 class _PyTime(enum.IntEnum): @@ -867,10 +869,6 @@ class TestPyTime_t(unittest.TestCase): # seconds (2 * SEC_TO_NS, (2, 0)), (-3 * SEC_TO_NS, (-3, 0)), -

@@ -914,6 +912,76 @@ class TestPyTime_t(unittest.TestCase): with self.subTest(nanoseconds=ns, timespec=ts): self.assertEqual(PyTime_AsTimespec(ns), ts)

+

+

+

+

+

+

+

+

+ if name == "main": unittest.main()

--- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -3452,6 +3452,42 @@ test_PyTime_AsTimespec(PyObject *self, P } #endif +static PyObject * +test_PyTime_AsMilliseconds(PyObject *self, PyObject *args) +{

+

+} + +static PyObject * +test_PyTime_AsMicroseconds(PyObject *self, PyObject *args) +{

+

+} + static PyMethodDef TestMethods[] = { {"raise_exception", raise_exception, METH_VARARGS}, @@ -3621,6 +3657,8 @@ static PyMethodDef TestMethods[] = { #ifdef HAVE_CLOCK_GETTIME {"PyTime_AsTimespec", test_PyTime_AsTimespec, METH_VARARGS}, #endif

--- a/Python/pytime.c +++ b/Python/pytime.c @@ -19,6 +19,10 @@ #define MS_TO_NS (MS_TO_US * US_TO_NS) #define SEC_TO_NS (SEC_TO_MS * MS_TO_NS) +/* Conversion from nanoseconds */ +#define NS_TO_MS (1000 * 1000) +#define NS_TO_US (1000) + static void error_time_t_overflow(void) { @@ -288,33 +292,29 @@ PyObject * } static _PyTime_t -_PyTime_Multiply(_PyTime_t t, unsigned int multiply, _PyTime_round_t round) +_PyTime_Divide(_PyTime_t t, _PyTime_t k, _PyTime_round_t round) {

} _PyTime_t _PyTime_AsMilliseconds(_PyTime_t t, _PyTime_round_t round) {

} -/* FIXME: write unit tests */ _PyTime_t _PyTime_AsMicroseconds(_PyTime_t t, _PyTime_round_t round) {

} static int