If you write JavaScript or TypeScript, you've probably felt the pain of Date—zero-indexed months, accidental in-place mutation, and timezone math that silently drifts on DST boundaries. The ECMAScript Temporal API finally fixes those foundations, and it's a huge step forward.
The catch is that Temporal is intentionally a low-level specification. Once you move past basic arithmetic, you still find yourself writing custom formatters, parsing inconsistent input strings, guarding against month-end drift in billing loops, and rolling your own helpers for weekends, DST transitions, or domain calendars.
Rather than wrapping legacy Date one more time, I built Tempo (tempo-kit v5.1) directly on Temporal—and paired it with tempo-fns (v1.3), a zero-dependency functional companion for developers who prefer standalone functions over a class wrapper.
1. Immutable, Temporal-Native Formatting & Ergonomics
Every Tempo instance is Object.freeze()d and backed by Temporal.ZonedDateTime. Operations like .add(), .subtract(), and .set() always return a fresh instance, and formatting uses readable multi-letter tokens instead of colliding single-letter codes:
import { Tempo } from 'tempo-kit';
const launch = new Tempo('2026-12-04T09:00:00', {
timeZone: 'Australia/Sydney',
locale: 'en-AU',
});
launch.format('{wkd}, {dd} {mmm} {yyyy}'); // → 'Friday, 04 Dec 2026'
2. Predicates That Read Like English (t.is.*)
A lot of date code is just asking yes/no questions: Is this a weekend? Is clocks-ahead DST active? Does this timestamp fall inside our billing window? In v5.1, every Tempo instance exposes a lazy-memoized t.is namespace that allocates nothing unless you read it:
launch.is.weekend(); // → false (uses [6, 7] for en-AU, [5, 6] for ar-SA)
launch.is.dst(); // → true (Sydney summer)
launch.is.between('2026-12-01', '2027-01-01'); // → true (half-open [) by default)
Because t.is is backed by Tempo's registry.predicates, you can also attach your own domain checks (like t.is.payday()) inside an isolated Tempo.extend() sandbox without polluting globals.
3. Stepped Iteration Without Month-End Drift
One of the oldest traps in scheduling code is iterating a monthly billing cycle by repeatedly adding { months: 1 }: Jan 31 + 1 month becomes Feb 28, and Feb 28 + 1 month becomes Mar 28. You lose the 31st permanently.
Interval.each() (and splitBy()) solves this by scaling calendar steps cumulatively from start, while keeping iteration lazy:
import { Tempo, Interval } from 'tempo-kit';
const billing = new Interval(
new Tempo('2026-01-31T00:00:00Z'),
new Tempo('2026-04-30T00:00:00Z'),
);
[...billing.each({ months: 1 })].map(d => d.format('{yyyy}-{mm}-{dd}'));
// → ['2026-01-31', '2026-02-28', '2026-03-31']
4. Keep Core Lean; Extend via Registry & Plugins
Most teams don't want a monolithic date library—and they don't want to fork a library just to add a custom format or domain calendar. Tempo splits configuration and extensions into two clean layers:
-
Declarative Registry (
Tempo.init({ registry })): Register custom parse layouts, format masks, localized number/weekday words, and customt.is.*predicates cleanly per configuration or sandbox. -
Opt-In Subpaths & Plugins: Need a minimal bundle? Import
tempo-kit/core. Need DST transition tracking ("when do the clocks change next?")? Opt in toDstTerm:
import { Tempo } from 'tempo-kit';
import { DstTerm } from 'tempo-kit/terms/daylight';
Tempo.use(DstTerm);
const now = new Tempo('2026-12-04T09:00:00', { timeZone: 'Australia/Sydney' });
now.term.dst; // → 'DST'
now.term.daylight.offset; // → '+11:00'
now.term.daylight.span.end.format('{yyyy}-{mm}-{dd}'); // → '2027-04-04'
5. Zero Syntax Migration Friction (@tempo-kit/plugin-dialects)
The biggest reason developers bounce off any new date library is simple: "I already have 200 Moment, Luxon, or strftime format strings in production, and I don't want to learn or rewrite them."
@tempo-kit/plugin-dialects lets you keep your existing Moment/Day.js, Unicode LDML/Luxon, POSIX strftime, Go, PHP, .NET, MySQL, or Oracle masks—or translate them into native Tempo tokens whenever you're ready:
import { Tempo } from 'tempo-kit';
import { DialectsPlugin } from '@tempo-kit/plugin-dialects';
Tempo.init({ dialect: 'moment', plugins: [DialectsPlugin] });
const t = new Tempo('2026-12-04T09:00:00Z');
t.format('YYYY-MM-DD'); // → '2026-12-04' (uses default 'moment')
t.format('%Y-%m-%d', { dialect: 'strftime' }); // → '2026-12-04' (per-call override)
Tempo.dialects.explain('MMM Do, YYYY', { dialect: 'moment' }).pattern;
// → '{mmm} {dd:ord}, {yyyy}'
6. Why We Stopped Letting LLMs Do Calendar Math (@tempo-kit/plugin-ai)
If you've ever asked an LLM for "the Friday before Melbourne Cup next year", you've probably seen the failure mode: the model knows the cultural rule (Melbourne Cup is the first Tuesday of November), then guesses what day of the week November 1st falls on, subtracts the wrong number of days, and returns a Saturday with 0.97 confidence.
LLMs are great at semantic intent and terrible at calendar arithmetic. So in @tempo-kit/plugin-ai, we split the job: parseAI() and extractAI() ask the model for a small structured plan (1st Tuesday of November 2027, then step back to Friday), and Tempo executes that plan deterministically on Temporal (Fri, 2027-10-29).
7. Prefer Pure Functions Over Temporal? Use tempo-fns
If you'd rather not adopt a wrapper class at all, tempo-fns (v1.3) gives you tree-shakeable, zero-dependency utilities that work directly on Temporal.*, Date, or ISO strings:
import { eachInterval, startOfMonth, endOfMonth } from 'tempo-fns';
startOfMonth('2024-02').toString(); // → '2024-02-01'
endOfMonth('2024-02').toString(); // → '2024-02-29'
[...eachInterval(
Temporal.PlainDate.from('2026-01-31'),
Temporal.PlainDate.from('2026-04-30'),
{ months: 1 },
)].map(d => d.toString());
// → ['2026-01-31', '2026-02-28', '2026-03-31']
Honest Trade-Offs Before You Adopt
Tempo isn't a 2 KB one-trick utility. If all your app ever does is toISOString().slice(0, 10), tempo-kit is more engine than you need—reaching for raw Temporal or tempo-fns will keep your bundle smaller and simpler.
Tempo also uses two-letter getters like .yy, .mm, .dd, .hh, .mi, and .ss instead of .year or .month. It takes less than five minutes to get used to, and after that it cuts down a surprising amount of visual noise across formatting and calendar logic.
(One quick runtime note for any Temporal-based stack, whether raw Temporal, tempo-fns, or tempo-kit: if your target browsers or runtimes don't ship native Temporal yet, you'll bundle @js-temporal/polyfill, and Tempo detects globalThis.Temporal automatically wherever native support is present.)
Try It Out & Share Your Feedback
- No-install browser sandbox: Online REPL
- Docs & Cookbooks: tempo-kit.web.app
-
Install:
npm install tempo-kit·npm install tempo-fns - Feedback & Bugs: Drop a comment below, start a thread in GitHub Discussions, or file a bug/feature request on GitHub Issues.
Top comments (0)