# splitIntervalByUnitTime

Industry: Core

## Signature

```ts
splitIntervalByUnitTime(start: string, end: string, unit: string, amount: number, options?: { maxPieces?: number; }): { start: string; end: string; }[]
```

Split a time interval into sub-intervals of `amount × unit`.

- Returns an array of `{ start, end }` records that tile the interval, each record's `end` equal to the next record's `start`.
- Every piece is half-open `[start, end)`: a boundary belongs only to the piece that starts there, so the pieces share no value and together cover the interval exactly once (the rule CORE-6's `splitIntervalAt` uses).
- The final sub-interval is trimmed so its `end` never exceeds the original `end`.
- Boundaries lie on the one day between `start` and `end`: `PlainTime` arithmetic wraps at midnight, but a step that reaches or passes midnight is past `end`, so that slice is trimmed to `end` (`"12:00"` to `"23:00"` by 12 hours is one slice).
- Returns `[{ start, end }]` when `start === end` (zero-length interval).
- Returns `[]` on invalid input (unparseable start/end, unsupported unit, non-positive amount, or a unit that has no effect on `PlainTime`, e.g. `"days"`).

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `start` | `string` | ISO PlainTime string for the interval start |
| `end` | `string` | ISO PlainTime string for the interval end |
| `unit` | `string` | duration unit string — `"hours" \| "minutes" \| "seconds" \| "milliseconds" \| "microseconds" \| "nanoseconds"` (calendar units are ignored by PlainTime and return []) |
| `amount` | `number` | positive number of units per step |

## Options

**options**

The limit on the size of the result

| 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 `{ start, end }` records, or [] on invalid input

**Members of each item**

| 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 can equal `start`, which makes the interval empty. |

## Examples

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

splitIntervalByUnitTime("12:00:00", "14:00:00", "hour", 1) // [{ start: "12:00:00", end: "13:00:00" }, { start: "13:00:00", end: "14:00:00" }]
```

## Source

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