mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +00:00
Issue #22117: Use the _PyTime_t API in _datetime.datetime() constructor
* Remove _PyTime_gettimeofday() * Add _PyTime_GetSystemClock()
This commit is contained in:
parent
10915aa85c
commit
09e5cf28ae
4 changed files with 35 additions and 124 deletions
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue