Skip to content

Determine whether two date ranges overlap

Test whether two date ranges intersect, triggered when caller compares two IDateRange instances.

Field Value
Operation ID OP-003
Trigger Caller compares two IDateRange instances
Inputs range1, range2, inAllowSameDateOverlap
Outputs Boolean
Primary components DateRangeExtensions.IsOverlapping(this IDateRange, IDateRange, Boolean inAllowSameDateOverlap = false)
Entry point Common/SAIF.Common/Extensions/DateRangeExtensions.cs

Steps

  1. Translate inAllowSameDateOverlap into an IncludeComparisons mode: true → Exclusive (touching endpoints are not an overlap), false → Inclusive. (BR-004)
  2. Guard: proceed only if range2 is non-null and both ranges pass IsValidRange(). Otherwise return false. (BR-001, BR-002)
  3. Return true if any of four conditions hold: range2.BeginDate falls inside range1; range2.EndDate falls inside range1; range1.BeginDate falls inside range2; or the ranges are exactly identical and not zero-length. Membership is evaluated by IComparableExtensions.IsBetween using the mode from step 1. (BR-003, BR-004)
  4. Otherwise return false.

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start([IsOverlapping called]) --> S1["Translate inAllowSameDateOverlap<br>into comparison mode"]
    S1 --> D1{"range2 non-null and<br>both ranges valid?"}
    D1 -->|No| R1([Return false])
    D1 -->|Yes| D2{"Any of 4 overlap<br>conditions true?"}
    D2 -->|Yes| R2([Return true])
    D2 -->|No| R3([Return false])

Sources

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