diff --git a/src/sla_monitor/app.py b/src/sla_monitor/app.py index d4f0657..a5ac69e 100644 --- a/src/sla_monitor/app.py +++ b/src/sla_monitor/app.py @@ -185,11 +185,17 @@ def _business_minutes_elapsed(since_utc, now_utc): while current < now: if current.weekday() < 5: - end_of_day = (current + timedelta(days=1)).replace( - hour=0, minute=0, second=0, microsecond=0 + # Count only the business-hours window [BH_START, BH_END) on this + # weekday. Clamp the day's span to the portion that overlaps + # [current, now); overnight hours (BH_END..next BH_START) are excluded. + day_start = current.replace( + hour=BH_START, minute=0, second=0, microsecond=0 ) - day_end = min(end_of_day, now) - total += (day_end - current).total_seconds() / 60 + day_close = current.replace(hour=BH_END, minute=0, second=0, microsecond=0) + span_start = max(current, day_start) + span_end = min(day_close, now) + if span_end > span_start: + total += (span_end - span_start).total_seconds() / 60 current = (current + timedelta(days=1)).replace( hour=0, minute=0, second=0, microsecond=0