/// <summary> /// Creates a new configuration after the last configuration on the list that goes from then until the next plate change. /// </summary> /// <returns></returns> public PlateConfiguration CreateNewConfig() { // default to one week ago if first thing. DateTime begin = DateTime.Today.AddDays(-7); DateTime end = begin; if (PlateConfigurations != null && PlateConfigurations.Count > 0) { begin = PlateConfigurations.Last().EndTime.AddDays(1); } if (PlateChangeDays.Count > 0) { while (PlateChangeDays.All(d => d != begin.DayOfWeek)) { begin = begin.AddDays(-1); } end = begin.AddDays(1); while (PlateChangeDays.All(d => d != end.DayOfWeek)) { end = end.AddDays(1); } end = end.AddDays(-1); } else { // default to a week end = begin.AddDays(7); } var plateChange = new PlateConfiguration(begin, end); PlateConfigurations?.Add(plateChange); return(plateChange); }