# clampInterval

Industry: Core

## Signature

```ts
clampInterval(interval: Interval, bounds: Interval): Interval | null
```

Return the part of `interval` that lies inside `bounds`, or null when none of it does.

- Exactly `intersectIntervals(interval, bounds)`: half-open, so an interval that only touches `bounds` clamps to `null`, as does an empty interval at an edge of `bounds`.
- Endpoints are the caller's own strings. Where an endpoint of `interval` and of `bounds` are the same instant, `interval`'s spelling is used (GMT rule: the first argument wins ties).
- For zone-aligned bounds (a local business day), build them with `floorToZone` first.
- Returns `null` on invalid input — either argument not an `Interval`, or inverted.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `interval` | `Interval` | `{ start, end }` record of ISO 8601 instant strings to clamp; its strings win ties |
| `bounds` | `Interval` | `{ start, end }` record of ISO 8601 instant strings to clamp into |

## Returns

`{ start, end }` inside `bounds`, or null when nothing remains or on invalid input

## Related types

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

## Examples

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

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

## Source

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