---
title: Compare two date ranges for equality
summary: Compare two date ranges for structural equality.
status: draft
owner: saif-docgen
last_reviewed: 2026-09-15
library: SAIF.Framework.Common
reference_type: package
operation_id: OP-015
trigger: Caller compares ranges
---

# Compare two date ranges for equality

Compare two date ranges for structural equality, triggered when caller compares ranges.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-015 |
| **Trigger** | Caller compares ranges |
| **Inputs** | Two ranges |
| **Outputs** | `Boolean` / `int` |
| **Primary components** | ``DateRange.operator ==` / `operator !=` / `Equals(object)` / `GetHashCode()`, and `DateRangeExtensions.IsEqual`` |
| **Entry point** | `Common/SAIF.Common/Classes/DateRange.cs` |

## Steps

1. `operator ==(DateRange d1, IDateRange d2)` returns true only when both `BeginDate` and `EndDate` match. ([BR-034](../business-rules.md#br-034-two-date-ranges-are-equal-if-and-only-if-both-begindate-and-enddate-match))
2. `operator !=` independently returns true when either endpoint differs — it is not implemented as `!(==)`. ([BR-034](../business-rules.md#br-034-two-date-ranges-are-equal-if-and-only-if-both-begindate-and-enddate-match))
3. `Equals(object obj)` type-checks for `IDateRange` and defers to `operator ==`; anything else returns `false`. ([BR-034](../business-rules.md#br-034-two-date-ranges-are-equal-if-and-only-if-both-begindate-and-enddate-match))
4. `GetHashCode()` returns the arithmetic sum of the two endpoint hash codes.
5. `DateRangeExtensions.IsEqual(range1, range2)` performs the same endpoint comparison but additionally null-guards `range2`, returning `false` when it is null. ([BR-034](../business-rules.md#br-034-two-date-ranges-are-equal-if-and-only-if-both-begindate-and-enddate-match))

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
	Start(["Caller compares<br>two date ranges"]) --> S1["operator ==: true only when<br>both BeginDate and EndDate match"]
	S1 --> S2["operator !=: independently checks<br>if either endpoint differs"]
	S2 --> S3["Equals(object): type-checks<br>IDateRange, defers to operator =="]
	S3 --> S4["GetHashCode(): sum of<br>both endpoint hash codes"]
	S4 --> S5["IsEqual: same comparison,<br>null-guards range2"]
	S5 --> End([Return comparison result])
```

## Failure and edge-case behavior

- The operators dereference both operands without null checks, so comparing against `null` raises `NullReferenceException`.*

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)

> **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/Classes/DateRange.cs`
- `Common/SAIF.Common/Extensions/DateRangeExtensions.cs`
