Determine whether a sequence of date ranges overlaps itself¶
Detect mutual overlap within a collection of date ranges, triggered when caller validates a set of periods for mutual exclusivity.
| Field | Value |
|---|---|
| Operation ID | OP-005 |
| Trigger | Caller validates a set of periods for mutual exclusivity |
| Inputs | ranges, option |
| Outputs | Boolean |
| Primary components | DateRangeExtensions.IsOverLapping(this IEnumerable<IDateRange>, OverlappingOptions option = DatesMayNotMatch) |
| Entry point | Common/SAIF.Common/Extensions/DateRangeExtensions.cs |
Steps¶
- If fewer than two ranges are supplied, return
false. (BR-008) - Order ranges ascending by
BeginDate. - Skip ranges whose begin and end are both sentinel values (
DateTime.MinValue/MaxValue) — treated as a "null date" and ignored (DateExtensions.IsMinOrMax). (BR-002, BR-009) - If the previous range is open-ended (
IsOpenEnded) and the current range has a real begin date, returntrueimmediately — an open-ended range swallows everything after it. (BR-002, BR-010) - Branch on
option:DatesMayMatchreports overlap whenrange.BeginDate < previous.EndDate;DatesMayNotMatch(default) reports overlap whenrange.BeginDate <= previous.EndDate, so touching endpoints count as an overlap. (BR-011) - Advance
previous; returnfalseif the loop completes with no overlap found.
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([IsOverLapping called]) --> D1{"Fewer than<br>2 ranges supplied?"}
D1 -->|Yes| R1([Return false])
D1 -->|No| S1["Order ranges ascending<br>by BeginDate"]
S1 --> S2["Skip ranges with sentinel<br>begin/end (null date)"]
S2 --> D2{"Previous open-ended and<br>current has real begin date?"}
D2 -->|Yes| R2([Return true])
D2 -->|No| D3{"Overlap per<br>selected option?"}
D3 -->|Yes| R3([Return true])
D3 -->|No| S3["Advance previous,<br>continue loop"]
S3 --> End([Return false])
Failure and edge-case behavior¶
- The
switchin step 5 sits outside the first/skip branch structure, so it also executes on the first iteration whilepreviousis stillnull, which would raise aNullReferenceException.*
Related documentation¶
Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.
Sources¶
Common/SAIF.Common/Extensions/DateRangeExtensions.cs