summaryrefslogtreecommitdiffstats
path: root/Python/pytime.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-09-04 21:57:25 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2015-09-04 21:57:25 (GMT)
commitadfefa527a32e711c1bea9c1ac32c20e9cce0660 (patch)
tree8e03b6d95d1f6f32780d8535aa5b60d411d0646f /Python/pytime.c
parent19bbb9af678040e8963edfcfdc30e9f87b106fb9 (diff)
downloadcpython-adfefa527a32e711c1bea9c1ac32c20e9cce0660.zip
cpython-adfefa527a32e711c1bea9c1ac32c20e9cce0660.tar.gz
cpython-adfefa527a32e711c1bea9c1ac32c20e9cce0660.tar.bz2
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.
Diffstat (limited to 'Python/pytime.c')
-rw-r--r--Python/pytime.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/Python/pytime.c b/Python/pytime.c
index d226389..0364473 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;