From adfefa527a32e711c1bea9c1ac32c20e9cce0660 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 4 Sep 2015 23:57:25 +0200 Subject: 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. --- Python/pytime.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Python/pytime.c') diff --git a/Python/pytime.c b/Python/pytime.c index d226389a7c..036447365c 100644 --- a/Python/pytime.c +++ b/Python/pytime.c @@ -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; -- cgit v1.2.1