Пример #1
0
 internal ClassTime CreateClassTime()
 {
     return(new ClassTime(
                Day,
                ClassHourTime.Parse(Start),
                ClassHourTime.Parse(End)
                ));
 }
Пример #2
0
        public ClassTime?IntersectWith(ClassTime other)
        {
            if (!Overlaps(other))
            {
                return(null);
            }

            return(new ClassTime(day, ClassHourTime.Max(start, other.start), ClassHourTime.Min(end, other.end)));
        }
Пример #3
0
        public ClassTime?UnionIfOverlapsOrContinousWith(ClassTime other)
        {
            if (OverlapsOrContinousWith(other))
            {
                var start = ClassHourTime.Min(this.start, other.start);
                var end   = ClassHourTime.Max(this.end, other.end);
                return(new ClassTime(day, start, end));
            }

            return(null);
        }
Пример #4
0
        public ClassTime(DayOfWeek day, ClassHourTime start, ClassHourTime end)
        {
            if (start > end)
            {
                throw new ArgumentException("start must be less than or equal to end.");
            }

            this.start = start;
            this.end   = end;
            this.day   = day;
        }
Пример #5
0
        private bool HasLaunchBreak()
        {
            for (DayOfWeek day = DayOfWeek.Sunday; day <= DayOfWeek.Saturday; day++)
            {
                var launchTime = new ClassTime(day, ClassHourTime.FromParts(12, false), ClassHourTime.FromParts(15, false));
                IEnumerable <ClassTime> intersection = ScheduleTimes.IntersectWith(launchTime);
                if (intersection.IsEmpty())
                {
                    continue;
                }

                ClassHourTime prevEnd = launchTime.Start;
                ClassHourTime currentStart;
                bool          validDay = false;
                foreach (ClassTime classTime in intersection)
                {
                    currentStart = classTime.Start;
                    if (HasAtLeastOneHourSpace(prevEnd, currentStart))
                    {
                        validDay = true;
                        break;
                    }

                    prevEnd = classTime.End;
                }

                if (!validDay)
                {
                    currentStart = launchTime.End;
                    if (HasAtLeastOneHourSpace(prevEnd, currentStart))
                    {
                        validDay = true;
                    }
                }
                if (!validDay)
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #6
0
 public bool Contains(ClassHourTime hour)
 {
     return(start < hour && hour < end);
 }
Пример #7
0
        private static bool HasAtLeastOneHourSpace(ClassHourTime prevEnd, ClassHourTime currentStart)
        {
            ClassTimeSpan diff = currentStart - prevEnd;

            return(diff.TotalHours >= 1);
        }