# splitIntervalAt

Industry: Core

## Signature

```ts
splitIntervalAt(interval: Interval, boundaries: string[]): Interval[]
```

Split a half-open interval at instant boundaries into consecutive half-open pieces.

- Each piece's `end` is the next piece's `start`; under `[start, end)` the pieces share no instant and together cover the interval exactly once.
- `boundaries` may be unsorted. Boundaries at or outside the interval's edges are dropped, so no piece is empty; duplicate instants keep their first occurrence's spelling (GMT rule).
- Endpoints are the caller's own strings: the interval's own `start`/`end`, and each boundary exactly as passed.
- Splitting an empty interval returns it unchanged, as a single piece.
- Never returns `[]` for valid input — that is the invalid-input sentinel alone.
- To split at zone-aligned boundaries (local midnights), build them with `floorToZone` or `bucketRange` first.
- Returns `[]` when `interval` is not a valid `Interval`, `boundaries` is not an array, or any boundary is not an ISO 8601 instant string — even one outside the interval.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `interval` | `Interval` | `{ start, end }` record of ISO 8601 instant strings to split |
| `boundaries` | `string[]` | array of ISO 8601 instant strings to split at |

## Returns

consecutive `{ start, end }` pieces covering `interval`, or [] on invalid input

## Related types

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

## Examples

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

splitIntervalAt({ start: "2024-01-01T09:00:00Z", end: "2024-01-01T17:00:00Z" }, ["2024-01-01T12:00:00Z"]) // [{ start: "2024-01-01T09:00:00Z", end: "2024-01-01T12:00:00Z" }, { start: "2024-01-01T12:00:00Z", end: "2024-01-01T17:00:00Z" }]
```

## Source

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