Skip to content

Commit 33f382f

Browse files
committed
handle -ve leftover_ns
1 parent 632eabd commit 33f382f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Modules/_datetimemodule.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3039,6 +3039,11 @@ delta_new(PyTypeObject *type, PyObject *args, PyObject *kw)
30393039
CLEANUP;
30403040
}
30413041

3042+
if (leftover_ns < 0) {
3043+
y = PyNumber_Subtract(x, PyLong_FromLong(1));
3044+
CLEANUP;
3045+
leftover_ns += 1000;
3046+
}
30423047
self = microseconds_to_delta_ex(x, type);
30433048
SET_TD_NANOSECONDS((PyDateTime_Delta *)self, leftover_ns);
30443049
Py_DECREF(x);

0 commit comments

Comments
 (0)