mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
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:
parent
19bbb9af67
commit
adfefa527a
4 changed files with 43 additions and 40 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue