The logic calculates dayOfWeek using toStartOfWeek().daysBetween(date) + 1 and then uses a custom daysToMonday formula. This is fragile and can miscompute the Monday start depending on Apex toStartOfWeek() behavior and org locale settings.
How to fix: Use the platform’s toStartOfWeek() directly for the week start:
onsiteGapWeekStart = input.onsiteStartDate.toStartOfWeek();
onsiteGapWeekEnd = onsiteGapWeekStart.addDays(6);
This is simpler and avoids off-by-N errors.
File: ScheduleHoursDistributor.cls (onsite gap block in generateCategoryScheduleExceptions)