Skip to content

Commit 152601f

Browse files
authored
Fix overflow in DateTime + negative Duration (#1279)
1 parent 4a3fcdf commit 152601f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/neo4j/time/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2730,7 +2730,7 @@ def __add__(self, other: _timedelta | Duration) -> DateTime:
27302730
t = self.time()._to_clock_time() + _ClockTime(
27312731
other.seconds, other.nanoseconds
27322732
)
2733-
days, seconds = _symmetric_divmod(t.seconds, 86400)
2733+
days, seconds = divmod(t.seconds, 86400)
27342734
date_ = self.date() + Duration(
27352735
months=other.months, days=days + other.days
27362736
)

tests/unit/common/time/test_datetime.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ def test_subtract_native_datetime_2(self) -> None:
311311
Duration(hours=24),
312312
DateTime(2024, 4, 1, 0, 30, 0),
313313
),
314+
(
315+
DateTime(2025, 1, 1, 13, 45, 30, 123456789),
316+
Duration(seconds=-50400),
317+
DateTime(2024, 12, 31, 23, 45, 30, 123456789),
318+
),
314319
(
315320
DateTime(2024, 3, 31, 0, 30, 0),
316321
timedelta(microseconds=1),
@@ -321,6 +326,11 @@ def test_subtract_native_datetime_2(self) -> None:
321326
timedelta(hours=24),
322327
DateTime(2024, 4, 1, 0, 30, 0),
323328
),
329+
(
330+
DateTime(2025, 1, 1, 13, 45, 30, 123456789),
331+
timedelta(seconds=-50400),
332+
DateTime(2024, 12, 31, 23, 45, 30, 123456789),
333+
),
324334
),
325335
)
326336
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)