# intervalDivideEquallyUnix

Industry: Core

## Signature

```ts
intervalDivideEquallyUnix(start: string | number, end: string | number, n: number, options?: { maxPieces?: number; }): { start: number; end: number; }[]
```

Split a Unix epoch interval into `n` equal-length sub-intervals.

- Returns an array of `n` half-open `[start, end)` records that tile the original interval: each record's `end` is the next record's `start` and belongs only to that next record, so the pieces share no value and together cover `[start, end)` exactly once.
- Each boundary is `start + round((end - start) · i / n)` in integers of the arguments' own epoch unit (there is no `epochUnit` option: seconds in give seconds out, milliseconds give milliseconds), taken in `bigint` so no product past 2^53 loses a unit: the split is exact whenever the total divides evenly by `n`, and within half a unit of the exact cut otherwise (an exact half rounds up). No time zone is involved.
- When `n` is larger than the number of whole epoch units in the interval, some pieces are empty (their `start` equals their `end`): the result always has exactly `n` pieces.
- `n === 1` returns the original interval unchanged, as a single-element array.
- A zero-length interval (`start === end`) returns `n` identical zero-length sub-intervals, each an empty `[start, start)` that holds no instant.
- Returns `[]` when `n` is not a positive integer, or on invalid input (`start`/`end` that is not a safe integer or numeric string of one — fractions, empty strings and values beyond ±(2^53 − 1) are invalid — or `start > end`).
- Returns `[]` before building any piece when `n` exceeds `options.maxPieces` or the longest possible array (2^32 - 1).

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `start` | `string` \| `number` | Unix epoch value, in the one unit all epoch arguments share — interval start |
| `end` | `string` \| `number` | Unix epoch value, in the one unit all epoch arguments share — interval end |
| `n` | `number` | number of equal sub-intervals to produce (positive integer) |

## Options

**options**

optional: the limit on the number of pieces

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `maxPieces?` | `number` | `1_000_000` | The most records the result may hold. A result that would hold more, or more than the longest possible array (2^32 - 1 elements), returns `[]` and none is built. A value that is not a positive safe integer also returns `[]`. |

## Returns

array of `n` `{ start, end }` records, 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 can equal `start`, which makes the interval empty. |

## Examples

```ts
import { intervalDivideEquallyUnix } from "@northguild/gmt/unix/interval";

intervalDivideEquallyUnix(0, 90000000, 3) // [{ start: 0, end: 30000000 }, { start: 30000000, end: 60000000 }, { start: 60000000, end: 90000000 }]
```

## Source

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