/// <summary> /// Tests for an overlap of given date ranges /// </summary> /// <param name="TestEndPoints">Set to true if you want to count the date range end points as an overlap and false if you don't care if the end points overlap.</param> /// <param name="Ranges">The set of date ranges that you want to test.</param> /// <returns>True if there is an overlap of the ranges. False if there is no overlap.</returns> public static bool HasOverlap(bool TestEndPoints, DateRange[] Ranges) { if (Ranges.Count() < 2) throw new Exception("Ranges count must be greater than 1"); var dates = new List<DateRange>(); dates.AddRange(Ranges); dates = dates.OrderBy(r => r.Start).ToList(); for (int i = 1; i <= dates.Count - 1; i++) { if (dates[i - 1].End > dates[i].Start) return true; if (TestEndPoints && dates[i - 1].End == dates[i].Start) return true; } return false; }
public OverlapPairs(DateRange First, DateRange Second) { this.First = First; this.Second = Second; }