Skip to content

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

  1. If fewer than two ranges are supplied, return false. (BR-008)
  2. Order ranges ascending by BeginDate.
  3. 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)
  4. If the previous range is open-ended (IsOpenEnded) and the current range has a real begin date, return true immediately — an open-ended range swallows everything after it. (BR-002, BR-010)
  5. Branch on option: DatesMayMatch reports overlap when range.BeginDate < previous.EndDate; DatesMayNotMatch (default) reports overlap when range.BeginDate <= previous.EndDate, so touching endpoints count as an overlap. (BR-011)
  6. Advance previous; return false if 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 switch in step 5 sits outside the first/skip branch structure, so it also executes on the first iteration while previous is still null, which would raise a NullReferenceException.*

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