# intervalIntersectionDate

Industry: Core

## Signature

```ts
intervalIntersectionDate(aStart: string, aEnd: string, bStart: string, bEnd: string): { start: string; end: string; } | null
```

Return the overlapping span of two date intervals, or null when they do not overlap.

- Uses `Temporal.PlainDate.compare` for comparison.
- Half-open: an interval holds every `t` with `start <= t < end`. The intersection is `[max(aStart, bStart), min(aEnd, bEnd))` when `aStart < bEnd && bStart < aEnd` (CORE-6's `intersectIntervals`), otherwise `null`.
- Touching intervals (`aEnd === bStart`) share no day and return `null`.
- An empty interval (`start === end`) intersects only an interval it lies strictly inside, and then returns itself.
- Returns `null` if either interval is invalid (`start > end`).
- Returns `null` on invalid input (wrong type, malformed strings).
- Accepts RFC 9557 calendar-annotated PlainDate strings — E5 (issue #78). Since the result is a date *value*, all four arguments must carry the *same* calendar tag (or all be bare ISO); a mismatch returns `null`. The output's tag is re-derived from the intersection span, never copied from an input.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `aStart` | `string` | ISO 8601 date string for the first interval start, optionally calendar-annotated |
| `aEnd` | `string` | ISO 8601 date string for the first interval end, optionally calendar-annotated |
| `bStart` | `string` | ISO 8601 date string for the second interval start, optionally calendar-annotated |
| `bEnd` | `string` | ISO 8601 date string for the second interval end, optionally calendar-annotated |

## Returns

`{ start, end }` with the overlapping span, or null on invalid input / no overlap / mismatched calendars

**Members**

| Member | Type | Description |
| --- | --- | --- |
| `start` | `string` | The date the interval begins on, as an ISO 8601 date (`YYYY-MM-DD`). It keeps a calendar annotation such as `[u-ca=hebrew]` when the inputs carry one. |
| `end` | `string` | The first date after the interval, in the same format as `start`. It is exclusive: the interval holds everything from `start` up to but not including this value. It can equal `start`, which makes the interval empty. |

## Examples

```ts
import { intervalIntersectionDate } from "@northguild/gmt/plain/interval";

intervalIntersectionDate("2024-01-01", "2024-06-30", "2024-04-01", "2024-12-31") // { start: "2024-04-01", end: "2024-06-30" }
```

## Source

[plain/interval/intervalIntersectionDate.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/plain/interval/intervalIntersectionDate.ts)
