# temporal-interval

> Interval class for use with Temporal Instant and PlainDateTime

Latest version **0.0.9** (published 2025-03-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install temporal-interval
pnpm add temporal-interval
yarn add temporal-interval
bun add temporal-interval
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.9 |
| Published | 2025-03-18 |
| First published | 2022-03-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=12 |
| Dependencies | 1 |
| Unpacked size | 73.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Franklin Davenport |
| Maintainers | sparebytes |
| Keywords | DateTime, Duration, Interval, Instant, Temporal |

## Links

- npm: https://www.npmjs.com/package/temporal-interval
- Repository: https://github.com/sparebytes/js-temporal-interval
- Homepage: https://github.com/sparebytes/js-temporal-interval#readme
- Issues: https://github.com/sparebytes/js-temporal-interval/issues
- npm.io page: https://npm.io/package/temporal-interval

## Dependencies (1)

- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.17.7

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 0.0.9 (latest) — 2025-03-18
- 0.0.8 — 2022-10-26
- 0.0.7 — 2022-03-19
- 0.0.6 — 2022-03-19
- 0.0.5 — 2022-03-19
- 0.0.4 — 2022-03-18
- 0.0.3 — 2022-03-18
- 0.0.2 — 2022-03-18
- 0.0.1 — 2022-03-18

## README

# Temporal Interval

An Interval object represents a half-open interval of one of the following:

- ZonedDateTime
- Instant
- PlainDateTime
- PlainDate
- PlainYearMonth

See [Stack Blitz Example](https://stackblitz.com/edit/temporal-interval)

## Installation

```sh
npm install @js-temporal/polyfill temporal-interval
```

## Usage

```ts
import { Temporal } from "@js-temporal/polyfill";

// run setTemporalPolyfill as early as possible
import Interval, { setTemporalPolyfill } from "temporal-interval";
setTemporalPolyfill(Temporal);

// ZonedDateTime Interval
const zonedDateTimeInterval = new Interval(
  Temporal.ZonedDateTime.from("2000-01-01[utc]"),
  Temporal.ZonedDateTime.from("2000-01-02[utc]"),
);

// Instant Interval
const instantInterval = new Interval(
  Temporal.Instant.from("2000-01-01Z"),
  Temporal.Instant.from("2000-01-02Z"),
);

// PlainDateTime Interval
const plainDateTimeInterval = new Interval(
  Temporal.PlainDateTime.from("2000-01-01"),
  Temporal.PlainDateTime.from("2000-01-02"),
);

// PlainDate Interval
const plainDateInterval = new Interval(
  Temporal.PlainDate.from("2000-01-01"),
  Temporal.PlainDate.from("2000-01-02"),
);

// PlainYearMonth Interval
const plainYearMonthInterval = new Interval(
  Temporal.PlainYearMonth.from("2000-01-01"),
  Temporal.PlainYearMonth.from("2000-01-02"),
);

function example({ interval, point, other, duration }) {
  const { log } = console;
  log("         start:", interval.start);
  log("           end:", interval.end);
  log("    contains():", interval.contains(point));
  log("      equals():", interval.equals(other));
  log("    encloses():", interval.encloses(other));
  log("    overlaps():", interval.overlaps(other));
  log("intersection():", interval.intersection(other));
  log("       union():", interval.union(other));
  log("  toDuration():", interval.toDuration());
  log("     iterate():", Array.from(interval.iterate(duration)));
  log("    toString():", interval.toString());
  log("JSON.stringify:", JSON.stringify(interval));
}

example({
  interval: instantInterval,
  point: instantInterval.start,
  duration: Temporal.Duration.from("PT1H"),
  other: new Interval(Temporal.Instant.from("2000-01-02Z"), Temporal.Instant.from("2000-01-03Z")),
});
```

---
_Source: https://npm.io/package/temporal-interval · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
