# intervalFromDurationDateTime

Industry: Core

## Signature

```ts
intervalFromDurationDateTime(value: string, duration: string, anchor: "start" | "end", options?: { overflow?: "reject" | "constrain" | undefined; }): { start: string; end: string; } | null
```

Construct a datetime interval from a single point plus an ISO 8601 duration, anchored at either end.

- `anchor: "start"` treats `value` as the interval start and adds `duration` to get the end.
- `anchor: "end"` treats `value` as the interval end and subtracts `duration` to get the start.
- Uses `Temporal.PlainDateTime.prototype.add`/`.subtract`, so calendar units (years/months/weeks) resolve against `value` itself — no separate `relativeTo` is needed, unlike `addDuration`.
- A negative `duration` (e.g. `"-P1D"`) can invert the computed span; returns null when that happens, mirroring `intervalIntersectionDateTime`'s `start > end` rejection.
- Returns null on invalid input (unparseable `value`, invalid `duration`, or an `anchor` other than `"start"`/`"end"`).

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `value` | `string` | ISO PlainDateTime string |
| `duration` | `string` | ISO 8601 duration string |
| `anchor` | `"start"` \| `"end"` | "start" \| "end" — which endpoint `value` represents |

## Options

**options**

How an out-of-range endpoint is handled

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `overflow?` | `"reject"` \| `"constrain"` ([`Overflow`](/gmt/reference/types/Overflow/)) | `"constrain"`, Temporal's default. | What to do when the computed endpoint is not a real date. `"constrain"` clamps it to the last valid day, so Jan 31 + 1 month is Feb 29 or 28; `"reject"` returns `null`. |

## Returns

`{ start, end }` with the constructed span, or null on invalid input

**Members**

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

## Related types

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

## Examples

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

intervalFromDurationDateTime("2024-01-01T00:00:00", "P1DT2H", "start") // { start: "2024-01-01T00:00:00", end: "2024-01-02T02:00:00" }
```

## Source

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