Issue #23517: Fix implementation of the ROUND_HALF_UP rounding mode in

datetime.datetime.fromtimestamp() and datetime.datetime.utcfromtimestamp().
microseconds sign should be kept before rounding.
This commit is contained in:
Victor Stinner 2015-09-04 23:57:25 +02:00
parent 19bbb9af67
commit adfefa527a
4 changed files with 43 additions and 40 deletions

View file

@ -82,10 +82,6 @@ _PyTime_DoubleToDenominator(double d, time_t *sec, long *numerator,
volatile double floatpart;
floatpart = modf(d, &intpart);
if (floatpart < 0) {
floatpart += 1.0;
intpart -= 1.0;
}
floatpart *= denominator;
if (round == _PyTime_ROUND_HALF_UP)
@ -98,6 +94,10 @@ _PyTime_DoubleToDenominator(double d, time_t *sec, long *numerator,
floatpart -= denominator;
intpart += 1.0;
}
else if (floatpart < 0) {
floatpart += denominator;
intpart -= 1.0;
}
assert(0.0 <= floatpart && floatpart < denominator);
*sec = (time_t)intpart;