summaryrefslogtreecommitdiff
path: root/date_calculator.py
diff options
context:
space:
mode:
authormatin <matin.kaufmann@gmail.com>2025-09-12 22:18:32 +0200
committermatin <matin.kaufmann@gmail.com>2025-09-12 22:18:32 +0200
commit6de01b3ee171e60e6609aea51ef7c9056736a017 (patch)
tree507de23a7db2d23725e5769249d76feab22a8717 /date_calculator.py
parent95d784fb414c6270e560fc0cf7ed289765ddd3ab (diff)
bug fix: corrected start date after end date for overlapping "Sonstige"
Diffstat (limited to 'date_calculator.py')
-rw-r--r--date_calculator.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/date_calculator.py b/date_calculator.py
index 576d6a1..cec4d40 100644
--- a/date_calculator.py
+++ b/date_calculator.py
@@ -64,14 +64,14 @@ class DateCalculator:
last_start, last_end, last_pid = adjusted[-1]
if start <= last_end:
- # Fully contained in previous period → discard
+ # Fully contained in previous period \u2192 discard
if end <= last_end:
continue
# Overlaps head; push start to the day after last_end
new_start = last_end + timedelta(days=1)
if new_start <= end:
adjusted.append((new_start, end, period_id))
- # else new_start > end → discard
+ # else new_start > end \u2192 discard
else:
adjusted.append((start, end, period_id))
@@ -104,6 +104,11 @@ class DateCalculator:
return non_overlapping_periods
@staticmethod
+ def filter_valid_periods(periods: List[Tuple[datetime, datetime, str]]) -> List[Tuple[datetime, datetime, str]]:
+ """Filter out periods where start date is after end date"""
+ return [(start, end, period_id) for start, end, period_id in periods if start <= end]
+
+ @staticmethod
def calculate_total_days(periods: List[Tuple[datetime, datetime, str]]) -> int:
"""Calculate total days across all periods"""
return sum((end - start).days + 1 for start, end, _ in periods)