Skip to content

Determine whether a sequence of date ranges is contiguous

Validate that consecutive date ranges connect with no gaps or overlaps, triggered when caller validates a set of consecutive coverage/effective periods.

Field Value
Operation ID OP-004
Trigger Caller validates a set of consecutive coverage/effective periods
Inputs ranges, option
Outputs Boolean
Primary components DateRangeExtensions.IsContiguous(this IEnumerable<IDateRange>, ContiguousOptions option = StartIsNextDay)
Entry point Common/SAIF.Common/Extensions/DateRangeExtensions.cs

Steps

  1. If fewer than two ranges are supplied, return true — a single range or empty set is trivially contiguous. (BR-005)
  2. Order the ranges ascending by BeginDate.
  3. Skip the comparison for the first element (no predecessor) and record it as previous.
  4. For each subsequent range branch on option: StartMatchesEnd requires range.BeginDate == previous.EndDate; StartIsNextDay (default) requires previous.EndDate.AddDays(1) == range.BeginDate; AllowGaps requires only range.BeginDate >= previous.EndDate. (BR-006, BR-007)
  5. On the first violation return false immediately. (BR-006)
  6. Advance previous and continue; return true if the loop completes.

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start([IsContiguous called]) --> D1{"Fewer than<br>2 ranges supplied?"}
    D1 -->|Yes| R1([Return true])
    D1 -->|No| S1["Order ranges ascending<br>by BeginDate"]
    S1 --> S2["Skip first range,<br>record as previous"]
    S2 --> D2{"Subsequent range violates<br>selected option's rule?"}
    D2 -->|Yes| R2([Return false])
    D2 -->|No| S3["Advance previous,<br>continue loop"]
    S3 --> End([Return true])

Sources

  • Common/SAIF.Common/Extensions/DateRangeExtensions.cs