# intervalIntersectionUtc

Industry: Core

## Signature

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

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

- 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 instant and return `null`.
- An empty interval (`start === end`) intersects only an interval it lies strictly inside, and then returns itself.
- Delegates to CORE-6's `intersectIntervals` once the arguments pass the UTC-string gate, and re-serialises the result, so it always equals that function's answer in canonical `Z` form.
- Returns `null` if either interval is invalid (`start > end`).
- Returns `null` on invalid input (wrong type, non-`Z` strings, malformed strings, leap seconds).

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `aStart` | `string` | ISO 8601 UTC datetime string for the first interval start |
| `aEnd` | `string` | ISO 8601 UTC datetime string for the first interval end |
| `bStart` | `string` | ISO 8601 UTC datetime string for the second interval start |
| `bEnd` | `string` | ISO 8601 UTC datetime string for the second interval end |

## Returns

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

**Members**

| Member | Type | Description |
| --- | --- | --- |
| `start` | `string` | The instant the interval begins at, as an ISO 8601 UTC string ending in `Z`. |
| `end` | `string` | The first instant 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 { intervalIntersectionUtc } from "@northguild/gmt/utc/interval";

intervalIntersectionUtc("2024-01-01T09:00:00Z", "2024-01-01T13:00:00Z", "2024-01-01T12:00:00Z", "2024-01-01T17:00:00Z") // { start: "2024-01-01T12:00:00Z", end: "2024-01-01T13:00:00Z" }
```

## Source

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