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¶
- If fewer than two ranges are supplied, return
true— a single range or empty set is trivially contiguous. (BR-005) - Order the ranges ascending by
BeginDate. - Skip the comparison for the first element (no predecessor) and record it as
previous. - For each subsequent range branch on
option:StartMatchesEndrequiresrange.BeginDate == previous.EndDate;StartIsNextDay(default) requiresprevious.EndDate.AddDays(1) == range.BeginDate;AllowGapsrequires onlyrange.BeginDate >= previous.EndDate. (BR-006, BR-007) - On the first violation return
falseimmediately. (BR-006) - Advance
previousand continue; returntrueif 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])
Related documentation¶
Sources¶
Common/SAIF.Common/Extensions/DateRangeExtensions.cs