Esempio n. 1
0
        public void FailInstanciate_NotTime()
        {
            var from = "15:99";
            var to = "15:00";

            var workDay = new Workday(from, to, SlotDuration.ThirtyMinutes);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the specified items as a <see cref="TimeSlotCollection"/> which start at the specified
        /// start date, ends at the specified date and where the start and end time are in range of a workday.
        /// </summary>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <param name="workday">The workday.</param>
        /// <returns></returns>
        public static TimeSlotCollection Create(DateTime from, DateTime to, Workday workday)
        {
            Assert.IsFalse(workday.Duration == SlotDuration.NotConfigured, "The duration of the workday should be configured");

            var result   = new List <DateRange>();
            var duration = workday.Duration.ToTimeSpan();

            var counter = 0;
            var i       = from.Date;

            while (i < to.AddDays(1).Date)
            {
                var j = i.Add(duration);

                if (workday.IsInRange(new DateRange(i, j)))
                {
                    result.Add(new DateRange(i, j));
                }
                i = j;

                // It is easy to make a mistake an fall into an infinite loops in such a case.
                // I test to avoid this, just in case ;)
                if (++counter >= 65535)
                {
                    throw new IndexOutOfRangeException(Messages.Error_TooManyLoops);
                }
            }
            return(TimeSlotCollection.Create(result));
        }
Esempio n. 3
0
        public void FailInstanciate_BeginsAfterEnds()
        {
            var from = "15:00";
            var to = "8:00";

            var workDay = new Workday(from, to, SlotDuration.ThirtyMinutes);
        }
Esempio n. 4
0
        public void CanTestInRange()
        {
            var dateTime = DateTime.Today.AddHours(16).AddMinutes(30);
            var workday = new Workday("08:00", "16:00", SlotDuration.ThirtyMinutes);

            Assert.IsFalse(workday.IsInRange(dateTime));
        }
Esempio n. 5
0
        public void CanInsanciate()
        {
            var from = "08:03";
            var to = "17:03";

            var workDay = new Workday(from, to, SlotDuration.ThirtyMinutes);

            Assert.AreEqual(8, workDay.From.Hour, "From hour is wrong");
            Assert.AreEqual(3, workDay.From.Minute, "From minute is wrong");

            Assert.AreEqual(17, workDay.To.Hour, "To hour is wrong");
            Assert.AreEqual(3, workDay.To.Minute, "To minute is wrong");
        }
        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");
        }
Esempio n. 7
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);
        }