temporal-fns

Getting started

Date-fns-style utilities for the Temporal API.

Experimental. The API and behavior may change.

ESM with TypeScript declarations and tree-shakable named imports. The library uses Temporal values directly.

Install

npm install @frantss/temporal-fns

A global Temporal is required. If your runtime does not provide it, install the polyfill:

npm install temporal-polyfill

Load it once in your application entry point, before using the library:

import 'temporal-polyfill/global';

For global TypeScript declarations, see TypeScript setup.

Usage

import { addBusinessDays, format, tryParse } from '@frantss/temporal-fns';

const reference = Temporal.PlainDate.from('2026-10-22');
const nextWorkingDate = addBusinessDays(reference, 1, { weekendDays: [5, 6] });

format(nextWorkingDate, 'yyyy-MM-dd'); // => '2026-10-25'

const [error, parsed] = tryParse('2024-02-29', 'yyyy-MM-dd', reference);
if (error === null) {
  parsed.toString(); // => '2024-02-29'
}

API reference

Browse all functions, input conventions, and exported types and options.

Each function has its own page with examples, related APIs, and links to the executable Gherkin behaviors. Calendar widget adapters use the @frantss/temporal-fns/calendar entry point.