diff options
Diffstat (limited to 'date_calculator.py')
| -rw-r--r-- | date_calculator.py | 9 |
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) |
