public void CanCreateTimeSlotCollection() { var from = DateTime.Today.AddHours(12); var to = DateTime.Today.AddHours(16); var workday = new Workday("13:00", "16:00", SlotDuration.ThirtyMinutes); var collection = TimeSlotCollection.Create(from, to, workday); Assert.AreEqual(6, collection.Count); Assert.AreEqual(13, collection[0].StartTime.Hour, "Start time hour should be 16"); Assert.AreEqual(0, collection[0].StartTime.Minute, "Start time minute should be 0"); Assert.AreEqual(16, collection[collection.Count - 1].EndTime.Hour, "End time hour should be 16"); Assert.AreEqual(0, collection[collection.Count - 1].EndTime.Minute, "End time minute should be 0"); }
public TimeSlotCollection GetSlots(DateTime startDate, DateTime endDate, Workday workday) { startDate = startDate.Date; endDate = endDate.Date; var slots = TimeSlotCollection.Create(startDate, endDate, workday); //Get appointments between start and end date. var appointments = (from a in this.Session.Query <Appointment>() where a.StartTime >= startDate && a.EndTime <= endDate.AddDays(1) select a).ToList(); //Remove slots that are overlapping with aleady taken meetings var result = (from slot in slots where IsNotOverlapping(appointments, slot) select slot); return(TimeSlotCollection.Create(result)); }
static void Main(string[] args) { TimeSlotCollection slots = new TimeSlotCollection(); slots.Add(new TimeSlot(new DateTime(2015, 1, 1, 9, 0, 0), new DateTime(2015, 1, 1, 10, 0, 0))); slots.Add(new TimeSlot(new DateTime(2015, 1, 1, 10, 0, 0), new DateTime(2015, 1, 1, 12, 0, 0))); slots.Add(new TimeSlot(new DateTime(2015, 1, 1, 14, 0, 0), new DateTime(2015, 1, 1, 15, 0, 0))); slots.Add(new TimeSlot(new DateTime(2015, 1, 1, 16, 0, 0), new DateTime(2015, 1, 1, 16, 30, 0))); TimeSlot withIn = new TimeSlot(new DateTime(2015, 1, 1, 8, 0, 0), new DateTime(2015, 1, 1, 18, 0, 0)); TimeSpan slotLength = TimeSpan.FromMinutes(60); TimeSlotCollection availableTimes = slots.FindAvailableSlots(slotLength, withIn); if (availableTimes != null) { foreach (var item in availableTimes) { Console.WriteLine(item); } } Console.WriteLine("Done!"); Console.ReadLine(); }