Issue #22117: Fix rounding of fromtimestamp() methods of datetime.datetime and

datetime.time: round towards minus infinity ("floor") instead of rounding
towards zero ("down").
This commit is contained in:
Victor Stinner 2015-03-30 01:10:14 +02:00
parent dca028b86a
commit e4a994d617
1 changed files with 3 additions and 2 deletions

View File

@ -2463,7 +2463,7 @@ date_local_from_object(PyObject *cls, PyObject *obj)
struct tm *tm; struct tm *tm;
time_t t; time_t t;
if (_PyTime_ObjectToTime_t(obj, &t, _PyTime_ROUND_DOWN) == -1) if (_PyTime_ObjectToTime_t(obj, &t, _PyTime_ROUND_FLOOR) == -1)
return NULL; return NULL;
tm = localtime(&t); tm = localtime(&t);
@ -4095,7 +4095,8 @@ datetime_from_timestamp(PyObject *cls, TM_FUNC f, PyObject *timestamp,
time_t timet; time_t timet;
long us; long us;
if (_PyTime_ObjectToTimeval(timestamp, &timet, &us, _PyTime_ROUND_DOWN) == -1) if (_PyTime_ObjectToTimeval(timestamp,
&timet, &us, _PyTime_ROUND_FLOOR) == -1)
return NULL; return NULL;
assert(0 <= us && us <= 999999); assert(0 <= us && us <= 999999);