public List <ScheduleEntry> GenerateSchedule(ScheduleGenerationRequest request) { var date = request.Date; //var week = WorkingWeek.GetThisOrUpcoming(date); var week = new WorkingWeek(date); var lastDueDayEntries = request.LastDueDayEntries; var lastEntryDate = lastDueDayEntries.LastOrDefault()?.Date; if (!date.IsWeekDay() || week.Contains(lastEntryDate)) { week = week.GetNext(); } if (lastEntryDate.HasValue) { //if week have entries or future entries exists just exit if (!week.IsAfter(lastEntryDate)) { return(new List <ScheduleEntry>()); } //entries is too old to consider var previousWeek = week.GetPrevious(); if (!previousWeek.Contains(lastEntryDate)) { lastDueDayEntries = new List <ScheduleEntry>(); } } var result = GenerateSchedule(request.Engineers, week, lastDueDayEntries); if (week.Contains(date)) //first call was for current week let generate one more { result.AddRange( GenerateSchedule( request.Engineers, week.GetNext(), result.TakeLast(Constants.ShiftsPerDay).ToList())); } return(result); }
public void WorkingWeek_Contains_Tests(DateTime weekDate, DateTime?checkDate, bool expected) { var week = new WorkingWeek(weekDate); Assert.Equal(expected, week.Contains(checkDate)); }