temporal-fns
API reference

Types and options

All types below are exported from @frantss/temporal-fns. Import them with import type. The exported Temporal namespace comes from temporal-spec and supplies types only; it does not install a runtime.

TypeScript setup

With TypeScript 6 or later, add ESNext.Temporal to your existing compilerOptions.lib entries so the global Temporal has declarations. With older TypeScript and the optional polyfill, load temporal-polyfill/types/global once alongside temporal-polyfill/global.

This setup supplies global types for the examples below. It does not replace the runtime setup.

Value types

TypeMeaningRelated APIs
CalendarValuePlainDate | PlainDateTime | ZonedDateTimeaddBusinessDays, startOfMonth
DateTimeValuePlainDateTime | ZonedDateTimeendOfDay
TimeValuePlainTime | DateTimeValueeachHourOfInterval
YearMonthValueCalendarValue | PlainYearMonthgetWeeksInMonth
QuarterValueYearMonthValue | PlainMonthDaygetQuarter
OrderedValueYearMonthValue | PlainTime | Instantmin, clamp
ParseReferenceYearMonthValue | PlainTime | PlainMonthDay | Instantparse
FormattableSame union as ParseReferenceformat
TemporalValueFormattable | Durationformat, formatDuration

These unions describe available information, not permission to mix kinds within one call. A collection or pair must have one concrete kind. Each function's entry lists its supported subset.

Behavior: supported and rejected kinds, declaration constraints.

import type { CalendarValue, Formattable, TemporalValue } from '@frantss/temporal-fns';

const date: CalendarValue = Temporal.PlainDate.from('2026-10-23');
const month: Formattable = Temporal.PlainYearMonth.from('2026-10');
const duration: TemporalValue = Temporal.Duration.from('PT1H');
date.toString(); // => '2026-10-23'
month.toString(); // => '2026-10'
duration.toString(); // => 'PT1H'

Interval and result types

TypeMeaningRelated APIs
Interval<T extends OrderedValue>{ start: T; end: T }; same-kind endpoints in ascending orderisWithinInterval, eachDayOfInterval
TryResult<T, E extends Error = Error>Readonly [null, T] | [E, null], labeled error then resulttryParse, tryParseDuration

Behavior: interval validity, tuple narrowing and readonly declarations.

import { isWithinInterval, tryParse } from '@frantss/temporal-fns';
import type { Interval, Temporal as TemporalTypes, TryResult } from '@frantss/temporal-fns';

const interval: Interval<TemporalTypes.PlainDate> = {
  start: Temporal.PlainDate.from('2026-10-01'),
  end: Temporal.PlainDate.from('2026-10-31'),
};
isWithinInterval(Temporal.PlainDate.from('2026-10-23'), interval); // => true
const result: TryResult<TemporalTypes.PlainDate, RangeError> = tryParse(
  '2026-10-23',
  'yyyy-MM-dd',
  interval.start,
);
if (result[0] === null) {
  result[1].toString(); // => '2026-10-23'
}
const failure: TryResult<TemporalTypes.PlainDate, RangeError> = tryParse(
  '2026-02-30',
  'yyyy-MM-dd',
  interval.start,
);
failure[1]; // => null

Week and business-day options

TypeFields and defaultsRelated APIs
Weekday0 | 1 | 2 | 3 | 4 | 5 | 6, Sunday through SaturdaynextDay, previousDay
WeekOptionsweekStartsOn?: Weekday, default 0startOfWeek, isSameWeek
WeekNumberOptionsWeekOptions plus firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7, default 1getWeek, getWeekYear
BusinessDayOptionsweekendDays?: readonly Weekday[], default [0, 6]addBusinessDays, isWeekend
BusinessDayDifferenceOptionsBusinessDayOptions plus optional timeZone; only applicable to zoned inputsdifferenceInBusinessDays
StepOptionsstep?: number, default 1; a positive safe integereachDayOfInterval, eachMinuteOfInterval

Behavior: week rules, weekend configuration, step validation.

import { addBusinessDays, getWeek, getWeekYear } from '@frantss/temporal-fns';
import type { BusinessDayOptions, WeekNumberOptions } from '@frantss/temporal-fns';

const isoWeek: WeekNumberOptions = { weekStartsOn: 1, firstWeekContainsDate: 4 };
const date = Temporal.PlainDate.from('2021-01-01');
getWeek(date, isoWeek); // => 53
getWeekYear(date, isoWeek); // => 2020
const fridaySaturday: BusinessDayOptions = { weekendDays: [5, 6] };
addBusinessDays(Temporal.PlainDate.from('2026-10-22'), 1, fridaySaturday).toString(); // => '2026-10-25'

Zone, formatting, and parsing options

TypeFields and defaultsRelated APIs
ZoneOptionstimeZone?: string, subject to the function's input-kind rulesisSameDay
RequiredZoneOptionstimeZone: stringformat with Instant
PlainOptionstimeZone?: never; excludes a zone overrideparse with plain references
FormatOptionsZoneOptions plus locale?: string, default en-USformat
ParseOptionsZoneOptions plus disambiguation?: 'compatible' | 'earlier' | 'later' | 'reject', default compatibleparse, tryParse, isMatch

The exported option interfaces are building blocks. Function overloads require or exclude timeZone according to the input kind; an option interface alone does not override those constraints.

Behavior: viewing zones, parsing zones and disambiguation, required context in TypeScript.

import { format, parse } from '@frantss/temporal-fns';
import type { FormatOptions, ParseOptions, RequiredZoneOptions } from '@frantss/temporal-fns';

const utc: FormatOptions & RequiredZoneOptions = { timeZone: 'UTC', locale: 'en-US' };
format(Temporal.Instant.from('2026-10-24T01:00Z'), 'HH:mm', utc); // => '01:00'
const policy: Omit<ParseOptions, 'timeZone'> = { disambiguation: 'later' };
const reference = Temporal.ZonedDateTime.from('2026-01-01T12:00[America/New_York]');
parse('2026-11-01 01:30', 'yyyy-MM-dd HH:mm', reference, policy).offset; // => '-05:00'

Distance and duration options

TypeFields and defaultsRelated APIs
DistanceOptionsZoneOptions plus locale?: string (en-US only), addSuffix?: boolean (false), includeSeconds?: boolean (false)formatDistance, formatDistanceToNow
StrictDistanceOptionsZoneOptions plus locale?: string (en-US only), addSuffix?: boolean (false), optional unit, roundingMethod (default round)formatDistanceStrict, formatDistanceToNowStrict
DurationUnitPlural component names: years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanosecondsformatDuration
DurationFormatOptionsformat?: readonly DurationUnit[] (all units), zero?: boolean (false), delimiter?: string (space), locale?: string (en-US only)formatDuration

Strict distance units are singular second, minute, hour, day, month, or year. Rounding methods are floor, ceil, round, or trunc. Duration formatting selects components without converting them; strict distance computes a total in one unit.

Behavior: relative options, duration selection and validation.

import { formatDistanceStrict, formatDuration } from '@frantss/temporal-fns';
import type { DurationFormatOptions, StrictDistanceOptions } from '@frantss/temporal-fns';

const strict: Omit<StrictDistanceOptions, 'timeZone'> = {
  unit: 'minute',
  roundingMethod: 'floor',
  addSuffix: true,
};
const base = Temporal.PlainDateTime.from('2026-01-01T00:00');
formatDistanceStrict(base.add({ seconds: 91 }), base, strict); // => 'in 1 minute'
const selected: DurationFormatOptions = { format: ['hours', 'minutes'], zero: true };
formatDuration(Temporal.Duration.from('PT1H'), selected); // => '1 hour 0 minutes'

Temporal namespace

Use the exported Temporal namespace in type annotations. Create runtime values using the global Temporal provided by your runtime or the installation setup.

Related: value types, interval and result types. Behavior: imports do not install Temporal.

import { format } from '@frantss/temporal-fns';
import type { Temporal as TemporalTypes } from '@frantss/temporal-fns';

const date: TemporalTypes.PlainDate = Temporal.PlainDate.from('2026-10-23');
const time: TemporalTypes.PlainTime = Temporal.PlainTime.from('12:30');
format(date, 'yyyy-MM-dd'); // => '2026-10-23'
format(time, 'HH:mm'); // => '12:30'