# intervalDifferenceUnix

Industry: Core

## Signature

```ts
intervalDifferenceUnix(aStart: string | number, aEnd: string | number, bStart: string | number, bEnd: string | number): { start: number; end: number; }[]
```

Return the portion(s) of the half-open interval A `[aStart, aEnd)` not covered by the half-open interval B `[bStart, bEnd)`.

- Compares numeric Unix epoch values directly, with the same rule as `subtractIntervals`.
- Every cut lands exactly on B's own `start` or `end`: the piece before B ends at `bStart`, which it excludes, and the piece after B starts at `bEnd`, which B excludes. No boundary is stepped by an epoch unit.
- Returns `[]` when B fully covers A, and when A is empty (`aStart === aEnd`).
- Returns `[{ start, end }]` when B overlaps one edge of A.
- Returns `[{ start, end }, { start, end }]` when B is fully inside A with gaps on both sides.
- Returns A unchanged when B lies entirely before or after it, touches it, or is empty.
- Returns `[]` if either interval is invalid (`start > end`).
- Returns `[]` on invalid input: non-numeric types, empty strings, and values that are not safe integers (fractions, `NaN`, `±Infinity`, beyond ±(2^53 − 1)).

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `aStart` | `string` \| `number` | Unix epoch value, in the one unit all epoch arguments share — first interval start |
| `aEnd` | `string` \| `number` | Unix epoch value, in the one unit all epoch arguments share — first interval end |
| `bStart` | `string` \| `number` | Unix epoch value, in the one unit all epoch arguments share — second interval start |
| `bEnd` | `string` \| `number` | Unix epoch value, in the one unit all epoch arguments share — second interval end |

## Returns

array of `{ start, end }` records representing A minus B, or `[]` on invalid input

**Members of each item**

| Member | Type | Description |
| --- | --- | --- |
| `start` | `number` | The instant the interval begins at, as a Unix epoch number in the unit the arguments share. |
| `end` | `number` | The first instant after the interval, in the same unit 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 { intervalDifferenceUnix } from "@northguild/gmt/unix/interval";

intervalDifferenceUnix(0, 1700000000, 1500000000, 1600000000) // [{ start: 0, end: 1500000000 }, { start: 1600000000, end: 1700000000 }]
```

## Source

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