Skip to content

Plugins (Adapters) — Overview

A plugin adapts one date library to the ITimeProvider pipeline. Install @time-provider/core plus exactly one plugin — the one matching the date type your codebase already uses.

PluginDate typeLocal timezone supportPeer dependency
plugin-nativeDateUTC-onlynone (built into JS)
plugin-dayjsdayjs.Dayjs✓ (via dayjs/plugin/timezone)dayjs
plugin-luxonDateTime (Luxon)luxon
plugin-momentmoment.MomentUTC-onlymoment
plugin-moment-timezonemoment.Moment✓ (via moment-timezone)moment, moment-timezone
plugin-temporalTemporal.ZonedDateTimenone (assumes a global Temporal)

Every plugin exports a ready-to-use singleton named plugin — from two entry points, mirroring @time-provider/core's own split (see Mental Model):

ts
// production
import { createTimeProvider } from "@time-provider/core";
import { plugin } from "@time-provider/plugin-dayjs";

const timeProvider = createTimeProvider.for(plugin).create();
ts
// tests
import { createTimeProvider } from "@time-provider/core/deterministic";
import { plugin } from "@time-provider/plugin-dayjs/deterministic";

const timeProvider = createTimeProvider.for(plugin).asFixed().withFixedTime(0).create();

createTimeProvider.for(plugin) returns a different (but structurally similar) builder depending on whether the plugin supportsLocalTime — that's what determines whether .withTimezone(...) and clock.localNow() exist on the result. See Timezones & Local Time.

Compare all six side-by-side — same expression, different date type — in the Playground.

Want to adapt a date library that isn't listed here? See Writing a Custom Plugin.