# intersectIntervals

Industry: Core

## Signature

```ts
intersectIntervals(a: Interval, b: Interval): Interval | null
```

Return the half-open interval two intervals share, or null when they share no instant.

- Non-null exactly when `intervalsOverlap(a, b)` is true: touching intervals return `null`.
- An empty interval strictly inside the other is returned as the intersection.
- Endpoints are the caller's own strings, never re-serialised. When `a` and `b` spell the same instant differently, `a`'s spelling is used (GMT rule: the first argument wins ties).
- The positional `intervalIntersectionUtc` (…) follow the same half-open rule and return re-serialised endpoints instead of echoing the caller's strings.
- Returns `null` on invalid input — either interval not an `Interval`, or inverted.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `a` | `Interval` | `{ start, end }` record of ISO 8601 instant strings; its strings win ties |
| `b` | `Interval` | `{ start, end }` record of ISO 8601 instant strings |

## Returns

`{ start, end }` of the shared span, or null when disjoint, touching, or on invalid input

## Related types

- [`Interval`](/gmt/reference/types/Interval/)

## Examples

```ts
import { intersectIntervals } from "@northguild/gmt/interval/calculate";

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

## Source

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