Skip to content

Tempo Plugin

@magmacomputing/tempo-plugin-dialects ​

npm version npm peer dependency version License TypeScript Ready

The Dialects Plugin enables Tempo to seamlessly format and parse dates using established external formatting standards, including Unicode LDML / UTS #35 (Luxon, date-fns), Moment.js / Day.js, and POSIX strftime (C, Python, Linux).

It provides transparent drop-in compatibility shims, multi-candidate fallback parsing, and an automated .explain() translation engine to assist incremental migrations to native Tempo {token} syntax.


🚀 Installation & Quickstart ​

bash
npm install @magmacomputing/tempo-plugin-dialects
Interactive Demo (@magmacomputing/tempo-plugin-dialects)
Open in Full REPL↗
// 🌐 External Dialect Formatting & Parsing
// Dynamic import of @magmacomputing/tempo-plugin-dialects
const { DialectsPlugin, DIALECT } = await import('@magmacomputing/tempo-plugin-dialects');
Tempo.use(DialectsPlugin);

const t = new Tempo('2026-10-24T15:30:45');

// 1. Luxon-style toFormat & LDML
console.log('Luxon drop-in .toFormat():', t.toFormat('dd LLL yyyy, HH:mm'));
console.log('Dialect namespace LDML:', t.dialects.ldml('yyyy/MM/dd HH:mm'));

// 2. POSIX strftime
console.log('strftime .strftime():', t.dialects.strftime('%Y-%m-%d %H:%M:%S'));
console.log('strftime auto-detect:', t.format('%A, %B %d %Y (%I:%M %p)', { dialect: DIALECT.Strftime }));

// 3. Flexible Multi-Candidate Parsing via Tempo.fromFormats()
const parsed = Tempo.fromFormats('24/10/2026 15:30', [
	'yyyy-MM-dd HH:mm',
	'dd/MM/yyyy HH:mm',
	'MM/dd/yyyy HH:mm',
]);
console.log('Parsed ISO (multi-candidate):', parsed.iso);

return t.toFormat('dd LLL yyyy (HH:mm:ss)');
Executes 100% in browser via native ESM sandbox

Registration ​

typescript
import { Tempo } from '@magmacomputing/tempo';
import { DialectsPlugin, DIALECT } from '@magmacomputing/tempo-plugin-dialects';

Tempo.use(DialectsPlugin);

const t = new Tempo('2026-10-24T15:30:45');

// Format using external dialect masks
console.log(t.format('yyyy-MM-dd HH:mm:ss', { dialect: DIALECT.Ldml })); // "2026-10-24 15:30:45"
console.log(t.format('%Y-%m-%d %H:%M:%S', { dialect: DIALECT.Strftime })); // "2026-10-24 15:30:45"
console.log(t.format('[Recorded on] MMMM Do YYYY', { dialect: DIALECT.Moment })); // "Recorded on October 24th 2026"

Zero-Boilerplate Auto-Installation (Side-Effect Import) ​

typescript
import { Tempo } from '@magmacomputing/tempo';
import '@magmacomputing/tempo-plugin-dialects/install';

const t = new Tempo('2026-10-24T15:30:45');
console.log(t.toFormat('dd LLL yyyy')); // "24 Oct 2026"

🔤 Supported Dialects ​

Dialect IdentifierCanonical ConstantCommon AliasesFormat ExamplePrimary Ecosystems
'ldml'DIALECT.Ldml'luxon', 'datefns', 'cldr'yyyy-MM-dd HH:mm:ss.SSSLuxon, date-fns, CLDR, Unicode UTS #35
'strftime'DIALECT.Strftime'posix', 'c', 'python'%Y-%m-%d %H:%M:%SPOSIX C, Python datetime, Linux Syslog, SQL
'moment'DIALECT.Moment'dayjs'YYYY-MM-DD HH:mm:ssMoment.js, Day.js

TIP

Native Tempo Syntax is Optimal While the Dialects plugin provides seamless interoperability with legacy format masks, native Tempo braced syntax ({token}) remains the most performant, lightweight, and expressive choice. Native Tempo syntax runs in Core with zero plugin dependencies, and provides rich capabilities unavailable in external token systems—including custom Terms, dynamic dot namespaces ({geo.city}), localized modifiers ({dow:locale}, {hh:locale:raw}), and regional {intl.*} property interpolation.


📚 API Surface Catalog ​

The Dialects plugin mounts cohesive static tools onto Tempo.dialects, instance utilities onto t.dialects, and attaches convenience shims directly onto Tempo:

API / MethodTargetInputReturnsDescription
t.toFormat(mask, options?)InstanceFormat mask string, optionsstringLuxon Drop-In Formatter. Formats the instance using LDML (or explicit dialect).
t.dialects.ldml(mask)InstanceUnicode LDML maskstringFast-path formatter for Unicode LDML / Luxon / date-fns masks.
t.dialects.strftime(mask)InstancePOSIX strftime maskstringFast-path formatter for POSIX strftime specifiers (%Y, %m, %d, etc.).
t.dialects.format(mask, dialect?)InstanceMask, dialect identifierstringGeneric dialect instance formatter with auto-detection for % specifiers.
t.dialects.explain(mask, dialect?)InstanceExternal format maskExplainResultAnalyzes mask and returns equivalent native Tempo {token} pattern and metadata.
Tempo.fromFormat(input, mask, options?)StaticDate string, mask, optionsTempoLuxon Drop-In Parser. Parses an input string using an LDML mask.
Tempo.fromFormats(input, masks[], options?)StaticDate string, candidate masksTempoMulti-candidate fallback parser (first matching mask succeeds).
Tempo.dialects.parse(input, mask, dialect?)StaticDate string, mask, dialectTempoExplicit dialect parser.
Tempo.dialects.fromFormats(input, masks[], ...)StaticDate string, candidate masksTempoExplicit multi-candidate fallback parser.
Tempo.dialects.explain(mask, dialect?)StaticExternal format maskExplainResultAST analyzer translating legacy masks into native Tempo {token} syntax.

📖 Architecture & Specialized Guides ​

To explore technical deep-dives, token compatibility matrices, and production patterns, consult the dedicated guides below:


⚡ Performance & Lazy Evaluation ​

  1. Pre-Compiled Formatters: Formatting masks are tokenized and compiled into high-speed closure interpolators on first run and cached in memory. Subsequent executions bypass tokenization and compilation overhead, evaluating directly through cached closures.
  2. Lazy-Evaluated Namespace: Accessing t.dialects utilizes Tempo's zero-overhead proxy pattern, consuming zero CPU cycles until explicitly invoked on an instance.
  3. Immutable Static Namespace: Tempo.dialects is recursively frozen via deepFreeze() to protect the host class against runtime tampering.

📄 Licensing ​

This is a Community plugin. It is completely free and open-source for personal and commercial use under the MIT license. No license token is required.

Released under the MIT License.