diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-03-29 22:09:18 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-03-29 22:09:18 (GMT) |
commit | 09e5cf28aef05ad07bf885c1b732eb567470199a (patch) | |
tree | e6c02fd1e758f7f6312d1651e20703565a33efb1 /Modules/_datetimemodule.c | |
parent | 10915aa85cf264caf6e606a10f1dd204663d6d5a (diff) | |
download | cpython-09e5cf28aef05ad07bf885c1b732eb567470199a.zip cpython-09e5cf28aef05ad07bf885c1b732eb567470199a.tar.gz cpython-09e5cf28aef05ad07bf885c1b732eb567470199a.tar.bz2 |
Issue #22117: Use the _PyTime_t API in _datetime.datetime() constructor
* Remove _PyTime_gettimeofday()
* Add _PyTime_GetSystemClock()
Diffstat (limited to 'Modules/_datetimemodule.c')
-rw-r--r-- | Modules/_datetimemodule.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 09285d9..c3e54f7 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -7,6 +7,10 @@ #include <time.h> +#ifdef MS_WINDOWS +# include <winsock2.h> /* struct timeval */ +#endif + /* Differentiate between building the core module and building extension * modules. */ @@ -4093,6 +4097,8 @@ datetime_from_timestamp(PyObject *cls, TM_FUNC f, PyObject *timestamp, if (_PyTime_ObjectToTimeval(timestamp, &timet, &us, _PyTime_ROUND_DOWN) == -1) return NULL; + assert(0 <= us && us <= 999999); + return datetime_from_timet_and_us(cls, f, timet, (int)us, tzinfo); } @@ -4103,10 +4109,14 @@ datetime_from_timestamp(PyObject *cls, TM_FUNC f, PyObject *timestamp, static PyObject * datetime_best_possible(PyObject *cls, TM_FUNC f, PyObject *tzinfo) { - _PyTime_timeval t; - _PyTime_gettimeofday(&t); - return datetime_from_timet_and_us(cls, f, t.tv_sec, (int)t.tv_usec, - tzinfo); + _PyTime_t ts = _PyTime_GetSystemClock(); + struct timeval tv; + + if (_PyTime_AsTimeval(ts, &tv, _PyTime_ROUND_FLOOR) < 0) + return NULL; + assert(0 <= tv.tv_usec && tv.tv_usec <= 999999); + + return datetime_from_timet_and_us(cls, f, tv.tv_sec, tv.tv_usec, tzinfo); } /*[clinic input] |