internal ClassTime CreateClassTime() { return(new ClassTime( Day, ClassHourTime.Parse(Start), ClassHourTime.Parse(End) )); }
public ClassTime?IntersectWith(ClassTime other) { if (!Overlaps(other)) { return(null); } return(new ClassTime(day, ClassHourTime.Max(start, other.start), ClassHourTime.Min(end, other.end))); }
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); }
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; }
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); }
public bool Contains(ClassHourTime hour) { return(start < hour && hour < end); }
private static bool HasAtLeastOneHourSpace(ClassHourTime prevEnd, ClassHourTime currentStart) { ClassTimeSpan diff = currentStart - prevEnd; return(diff.TotalHours >= 1); }