# intervalUnionTime

Industry: Core

## Signature

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

Return the combined span of two time intervals, or null when they are disjoint.

- Uses `Temporal.PlainTime.compare` for comparison.
- Half-open: an interval holds every `t` with `start <= t < end`. The union is returned only when it is one non-empty interval — the single run CORE-6's `mergeIntervals` would give.
- Overlapping intervals, and touching intervals (`aEnd === bStart`), return their combined span.
- Two **non-empty** intervals with any gap between them return `null`, even a one-unit gap. The caveat matters: an empty interval is the empty set, so it is never “separated” from anything. A non-empty interval unioned with an empty one far away is still that non-empty interval — see the next bullet — not `null`.
- An empty interval (`start === end`) is the empty set: it adds nothing, so the union is the other interval. Two empty intervals have no non-empty union and return `null`.
- Returns `null` if either interval is invalid (`start > end`).
- Returns `null` on invalid input (wrong type, malformed strings).

## Parameters

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

## Returns

`{ start, end }` with the merged span, or null on invalid input / disjoint intervals

**Members**

| Member | Type | Description |
| --- | --- | --- |
| `start` | `string` | The clock time the interval begins at, as an ISO 8601 time string with no date, offset or time zone. |
| `end` | `string` | The first clock time 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 is always later than `start`. |

## Examples

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

intervalUnionTime("09:00:00", "17:00:00", "12:00:00", "18:00:00") // { start: "09:00:00", end: "18:00:00" }
```

## Source

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