public void Can_calculate_slotsAmount_from_timespan() { int amount = 0; TimeSlot timeslot = new TimeSlot(0,new Time(8,0), new TimeSpan(0,0,5,0),true); TimeSpan timespan = new TimeSpan(0,0,45,0); amount = timeslot.GetSlotsAmount(timespan); Assert.AreEqual(9,amount); timespan = new TimeSpan(0,0,44,0); amount = timeslot.GetSlotsAmount(timespan); Assert.AreEqual(9, amount); timespan = new TimeSpan(0, 0, 46, 0); amount = timeslot.GetSlotsAmount(timespan); Assert.AreEqual(10, amount); }
public void Can_calculate_slotsAmount_from_workingHours() { int amount = 0; TimeSlot timeslot = new TimeSlot(0,new Time(0,0), new TimeSpan(0,0,15,0),true ); IDayWorkingHours dayWorkingHours = new DayWorkingHours(new Time(8, 0), new Time(15, 30), new Time(11, 30), new TimeSpan(0, 0, 30, 0)); amount = timeslot.GetSlotsAmount(dayWorkingHours); Assert.AreEqual(30,amount); dayWorkingHours = new DayWorkingHours(new Time(8, 0), new Time(15, 35), new Time(11, 30), new TimeSpan(0, 0, 30, 0)); amount = timeslot.GetSlotsAmount(dayWorkingHours); Assert.AreEqual(31,amount); dayWorkingHours = new DayWorkingHours(new Time(8, 0), new Time(15, 20), new Time( 11, 30), new TimeSpan(0, 0, 30, 0)); amount = timeslot.GetSlotsAmount(dayWorkingHours); Assert.AreEqual(30, amount); dayWorkingHours = new DayWorkingHours(new Time(8,0),new Time(15,30),new Time(12,0),new TimeSpan(0,0,0) ); amount = timeslot.GetSlotsAmount(dayWorkingHours); Assert.AreEqual(30, amount); }
private List<ITimeSlot> CreateTimeSlots(IDayWorkingHours dayWorkingHours,int slotDurationInMin) { List<ITimeSlot> timeSlots = new List<ITimeSlot>(); List<ITimeSlot> whTimeSlots = dayWorkingHours.GetWorkingHours(); whTimeSlots.Sort((ts1, ts2) => ts1.StartTime.CompareTo(ts2.StartTime)); Time firstSlotTime = whTimeSlots[0].StartTime; TimeSpan timeSlotDuration = new TimeSpan(0,slotDurationInMin,0); ITimeSlot slot = new TimeSlot(1,firstSlotTime,timeSlotDuration,true); // first timeslot int amountOfTimeSlots = slot.GetSlotsAmount(dayWorkingHours.GetWorkDayDuration()); if (amountOfTimeSlots > 0) { timeSlots.Add(slot); for (int i = 1; i < amountOfTimeSlots; i++) { Time nextSlotTime = slot.StartTime.Add(slot.Duration); if (whTimeSlots.Any(ts=> ts.StartTime <= nextSlotTime && nextSlotTime < ts.StartTime.Add(ts.Duration))) { slot = new TimeSlot(i + 1, slot.StartTime.Add(slot.Duration), timeSlotDuration, true); } else { slot = new TimeSlot(i + 1, slot.StartTime.Add(slot.Duration), timeSlotDuration, false); } timeSlots.Add(slot); } } return timeSlots; }