---
title: Determine whether a sequence of date ranges is contiguous
summary: Validate that consecutive date ranges connect with no gaps or overlaps.
status: draft
owner: saif-docgen
last_reviewed: 2026-09-15
library: SAIF.Framework.Common
reference_type: package
operation_id: OP-004
trigger: Caller validates a set of consecutive coverage/effective periods
---

# 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](../business-rules.md#br-005-a-set-of-fewer-than-two-date-ranges-is-always-contiguous))
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](../business-rules.md#br-006-contiguity-is-evaluated-on-ranges-sorted-ascending-by-begindate%2C-and-fails-on-the-first-violating-pair), [BR-007](../business-rules.md#br-007-the-default-contiguity-mode-is-startisnextday))
5. On the first violation return `false` immediately. ([BR-006](../business-rules.md#br-006-contiguity-is-evaluated-on-ranges-sorted-ascending-by-begindate%2C-and-fails-on-the-first-violating-pair))
6. Advance `previous` and continue; return `true` if the loop completes.

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
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
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)

## Sources
- `Common/SAIF.Common/Extensions/DateRangeExtensions.cs`
