private void createTimeSlots(DateTime startTime, DateTime endTime) { /* * Start: * 1. Start is between first ts and last ts * - do nothing * 2. Start is before first ts * - create timeslots before * 3. Start is after the last ts * - create timeslots after * * End: * 4. Start is between first ts and last ts * - do nothing * 5. End is after last ts * - create timeslots after */ if (timeslots.Count == 0) { int numTimeslots = calculateDifferenceInTimeslots(endTime, startTime); for (int i = 0; i < numTimeslots; i++) { DateTime newDT = startTime.AddMinutes(i * Constants.timeslotDuration); timeslots.Add(new Timeslot(newDT, Constants.timeslotDuration)); } return; } DateTime firstTime = timeslots[0].getTimeslotStartTime(); int startIndex = calculateDifferenceInTimeslots(startTime, firstTime); if (startIndex < 0) { // 2 for (int i = startIndex; i < 0; i++) { DateTime newDT = timeslots[0].getTimeslotStartTime().AddMinutes(-1 * Constants.timeslotDuration); timeslots.Insert(0, new Timeslot(newDT, Constants.timeslotDuration)); } } DateTime lastTime = timeslots[timeslots.Count - 1].getTimeslotStartTime(); int endIndex = timeslots.Count - 1 + calculateDifferenceInTimeslots(endTime, lastTime); if (endIndex > timeslots.Count) { // 5 for (int i = timeslots.Count; i < endIndex; i++) { Timeslot last = timeslots[timeslots.Count - 1]; DateTime newDT = last.getTimeslotStartTime().AddMinutes(Constants.timeslotDuration); timeslots.Add(new Timeslot(newDT, Constants.timeslotDuration)); } } }