API
@agape/temporal

Temporal Namespace

The Temporal namespace provides typed access to Temporal classes with intelligent fallback.

API

Description

The Temporal namespace provides typed access to Temporal classes with intelligent fallback.

This namespace automatically detects and uses the best available Temporal implementation:

  1. Agape-level temporal (set via setTemporal())
  2. GlobalThis temporal (native or polyfill)
  3. Stub implementation (throws helpful errors)

Usage

Use Temporal if Available

import { Temporal, hasTemporal } from '@agape/temporal';

if (hasTemporal()) {
  const now = Temporal.PlainDateTime.from('2025-09-19T10:00');
  console.log(now.toString());
}

Throw an Error if it's not

import { Temporal, TemporalNotAvailableError } from '@agape/temporal';

try {
  const date = Temporal.PlainDate.from('2025-09-19');
} catch (error) {
  if (error instanceof TemporalNotAvailableError) {
    console.error('Temporal is not available:', error.message);
  }
}

Use A Global Polyfill

import type { Temporal as TemporalPolyfill } from "@js-temporal/polyfill";
(globalThis as any)['Temporal'] = TemporalPolyfill;

import { Temporal, hasTemporal } from '@agape/temporal';
Temporal.PlainDateTime === TemporalPolyfill.PlainDateTime;

Set Agape Polyfill

import type { Temporal as TemporalPolyfill } from "@js-temporal/polyfill";
import { Temporal, setTemporal } from '@agape/temporal';
setTemporal(TemporalPolyfill)

Temporal.PlainDateTime === TemporalPolyfill.PlainDateTime;