# `InstantRange`

The instants from `start` up to but not including `end`, written `2026-10-25T09:00:00Z/2026-10-25T17:00:00Z`.

[Time and calendar](types.md#time-and-calendar); not ordered; since Jadpo 0.1.0.

## Make one

Build one from its fields, `InstantRange { start: ...  end: ... }`.

`text.parse(raw, as: InstantRange)` reads one from its text; text that isn't one at all fails `malformed`, such as `2026-10-25T09:00:00Z` or `2026-10-25T09:00:00Z/tomorrow`.

These operations give one: `range.intersection`, `temporal.day_bounds`, `temporal.month_bounds`, `temporal.week_bounds` and `temporal.year_bounds`.

Its parts keep these rules; a value that breaks one fails with the rule's name:

- `start_not_after_end`: `start <= end`

## Fields

| Field | Type |
|---|---|
| `start` | [`Instant`](type-instant.md) |
| `end` | [`Instant`](type-instant.md) |

## Text, JSON and storage

`text.from` writes its canonical text, the one form `text.parse` reads back. JSON sends an object of its parts.

| Text | JSON |
|---|---|
| `2026-10-25T09:00:00Z/2026-10-25T17:00:00Z` | `{"start":"2026-10-25T09:00:00Z","end":"2026-10-25T17:00:00Z"}` |

It is stored in one column named for the field, of type `tstzrange`. `2026-10-25T09:00:00Z/2026-10-25T17:00:00Z` is stored as `tstzrange('2026-10-25 09:00:00.000000+00'::timestamptz, '2026-10-25 17:00:00.000000+00'::timestamptz, '[)')`.

## Shown to people

`text.format(value, locale:)` shows it to people in their locale. A call also gives `zone:` and `format:`.

With `locale: Locale.en_gb`, `zone: Zone.europe_london` and `format: TimeFormat.date_time_medium`:

| Value | Shown |
|---|---|
| `2026-10-25T09:00:00Z/2026-10-25T17:00:00Z` | `25 Oct 2026, 09:00:00 – 25 Oct 2026, 17:00:00` |

## Operations

- `range.contains(range: Range<T>, value: T) -> Bool`: Whether `value` is inside `range`.
- `range.intersection(a: Range<T>, b: Range<T>) -> Range<T>?`: The part `a` and `b` share; `none` when they don't overlap.
- `range.overlaps(a: Range<T>, b: Range<T>) -> Bool`: Whether `a` and `b` share at least one value.
- `temporal.day_bounds(date: CalendarDate, zone: Zone) -> InstantRange`: The instants `date` runs between in `zone`: 23, 24 or 25 hours.
- `temporal.month_bounds(date: CalendarDate, zone: Zone) -> InstantRange`: The month holding `date` in `zone`.
- `temporal.week_bounds(date: CalendarDate, zone: Zone, starts_on: Weekday) -> InstantRange`: The week holding `date` in `zone`, starting on `starts_on`.
- `temporal.year_bounds(date: CalendarDate, zone: Zone) -> InstantRange`: The year holding `date` in `zone`.

Like every standard type, it also has the contract's own operations: `text.parse`, `text.from`, `text.format`, `json.read`, `json.write` and `==`. It isn't ordered, so `<` and sorting don't take it. [Every standard type meets one contract](../topics/every-standard-type-meets-one-contract.md) says how they work.
