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), POSIX strftime (C, Python, Linux), Moment.js / Day.js, and Oracle / SQL TO_CHAR (PostgreSQL, Snowflake, Redshift).

It provides transparent drop-in compatibility shims, multi-candidate fallback parsing, an automated .explain() ingestion engine, .export() for emitting dialect models from Tempo tokens, and .convert() for direct bidirectional transpilation between external ecosystems.


Key Features ​

  • Drop-In Formatter Compatibility: t.toFormat(mask) (Luxon), t.dialects.strftime(mask) (POSIX), t.dialects.oracle(mask) (SQL), t.dialects.moment(mask) (Moment/Day.js), and more.
  • Multi-Candidate Fallback Parsing: Tempo.fromFormats(input, masks[]) tries candidates in order and returns on first successful match.
  • Automated Dialect Ingestion: .explain(mask) translates any legacy format mask into equivalent native Tempo {token} syntax with reasoning metadata.
  • Bidirectional Transpilation: .convert(mask, from, to) converts format strings directly between any two supported dialects.
  • 9 Supported Dialects: LDML (Luxon/date-fns), strftime (POSIX/C/Python), Moment/Day.js, Oracle/SQL, PHP, Go, MySQL, .NET, and Spreadsheet (Excel/Sheets).
  • Lazy-Evaluated & Immutable: Zero overhead until invoked; Tempo.dialects is recursively frozen against tampering.

Installation ​

bash
npm install @magmacomputing/tempo-plugin-dialects

Quickstart ​

Interactive Demo (@magmacomputing/tempo-plugin-dialects)
Open in Full REPL↗
// 🌐 External Dialect Formatting, Parsing & Transpilation
// 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.123');

// 1. Format across external ecosystems
console.log('Luxon / LDML:', t.toFormat('dd LLL yyyy, HH:mm'));
console.log('POSIX strftime:', t.dialects.strftime('%Y-%m-%d %H:%M:%S'));
console.log('Oracle / SQL TO_CHAR:', t.dialects.oracle('YYYY-MM-DD HH24:MI:SS'));
console.log('.NET DateTime:', t.dialects.dotnet('yyyy-MM-dd HH:mm:ss.fff'));
console.log('MySQL DATE_FORMAT:', t.dialects.mysql('%Y-%m-%d %H:%i:%s'));
console.log('Excel / Sheets:', t.dialects.sheet('yyyy-mm-dd hh:mm:ss'));

// 2. Ingest & Explain legacy masks into native Tempo {token} syntax
const inspection = Tempo.dialects.explain('[Report for] MMMM Do, YYYY [at] hh:mm A', DIALECT.Moment);
console.log('Explained Moment -> Tempo IR:', inspection.pattern);

// 3. Export canonical Tempo templates to external dialect models
const sqlExport = Tempo.dialects.export('{yyyy}-{mm}-{dd} {hh}:{mi}:{ss}', DIALECT.Oracle);
console.log('Exported Tempo -> SQL TO_CHAR model:', sqlExport.pattern);
const sheetExport = Tempo.dialects.export('{yyyy}-{mm}-{dd} {hh}:{mi}:{ss}', DIALECT.Sheet);
console.log('Exported Tempo -> Spreadsheet mask:', sheetExport.pattern);

// 4. Universal Cross-Dialect Transpilation (.convert)
const posixToOracle = Tempo.dialects.convert('%Y-%m-%d %H:%M:%S', DIALECT.Strftime, DIALECT.Oracle);
console.log('Converted POSIX -> Oracle:', posixToOracle.pattern);

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

return `Transpiled POSIX to Oracle: ${posixToOracle.pattern}`;
Executes 100% in browser via native ESM sandbox
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"

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
'moment'DIALECT.Moment'dayjs'YYYY-MM-DD HH:mm:ssMoment.js, Day.js
'oracle'DIALECT.Oracle'sql', 'postgres', 'postgresql', 'snowflake', 'redshift', 'to_char'YYYY-MM-DD HH24:MI:SSOracle, PostgreSQL, Snowflake, AWS Redshift
'php'DIALECT.Php'laravel', 'wordpress'Y-m-d H:i:sPHP, Laravel, WordPress, Symfony
'go'DIALECT.Go'golang'2006-01-02 15:04:05Go (time.Format, time.Parse)
'mysql'DIALECT.Mysql'mariadb'%Y-%m-%d %H:%i:%sMySQL, MariaDB (DATE_FORMAT)
'dotnet'DIALECT.DotNet'csharp', '.net', 'c#'yyyy-MM-dd HH:mm:ss.fff.NET, C#, PowerShell (DateTime.ToString)
'sheet'DIALECT.Sheet'spreadsheet', 'excel', 'sheets'yyyy-mm-dd hh:mm:ss AM/PMMicrosoft Excel, Google Sheets, LibreOffice Calc

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 Reference ​

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.oracle(mask)InstanceOracle / SQL maskstringFast-path formatter for Oracle / PostgreSQL / Snowflake format models (YYYY, HH24, MI, etc.).
t.dialects.sql(mask)InstanceSQL / Oracle maskstringConvenience alias for t.dialects.oracle(mask).
t.dialects.php(mask)InstancePHP date maskstringFast-path formatter for PHP date() specifiers (Y, m, d, H, i, s, etc.).
t.dialects.go(mask)InstanceGo reference maskstringFast-path formatter for Go reference time layout (2006, 01, 02, 15, 04, 05).
t.dialects.mysql(mask)InstanceMySQL format maskstringFast-path formatter for MySQL / MariaDB DATE_FORMAT specifiers (%Y, %m, %d, %H, %i, %s, etc.).
t.dialects.dotnet(mask)Instance.NET format maskstringFast-path formatter for .NET / C# DateTime.ToString custom format strings (yyyy, MM, dd, HH, mm, ss, fff, etc.).
t.dialects.sheet(mask)InstanceSpreadsheet maskstringFast-path formatter for Excel / Google Sheets custom format strings (yyyy, mm, dd, hh, ss, AM/PM, etc.).
t.dialects.format(mask, dialect?)InstanceMask, dialect identifierstringGeneric dialect instance formatter with auto-detection for %, Go, SQL, MySQL, .NET, and Sheet specifiers.
t.dialects.explain(mask, dialectOrOptions?)InstanceExternal format mask, dialect name or { dialect }ExplainResultAnalyzes mask and returns equivalent native Tempo {token} pattern and metadata.
t.dialects.export(pattern, dialectOrOptions?)InstanceNative Tempo pattern, target dialect name or { dialect }ExportResultExports a native Tempo {token} pattern into an external dialect format model.
t.dialects.convert(mask, toOrOptions) / convert(mask, from, to)InstanceMask, target dialect, or { from, to } optionsConvertResultConverts a format mask directly from one dialect to another (source dialect auto-inferred if omitted).
Tempo.fromFormat(input, mask, options?)StaticDate string, mask, optionsTempoLuxon Drop-In Parser. Parses an input string using an LDML mask (or auto-detected dialect).
Tempo.fromFormats(input, masks[], options?)StaticDate string, candidate masksTempoMulti-candidate fallback parser with auto-dialect detection (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, dialectOrOptions?)StaticExternal format mask, dialect name or { dialect }ExplainResultAST analyzer translating legacy masks into native Tempo {token} syntax.
Tempo.dialects.export(pattern, dialectOrOptions?)StaticNative Tempo pattern, target dialect name or { dialect }ExportResultExports a native Tempo {token} pattern into an external dialect format model.
Tempo.dialects.convert(mask, toOrOptions) / convert(mask, from, to)StaticMask, target dialect, or { from, to } optionsConvertResultTranspiles a format mask directly between dialects (source dialect auto-inferred if omitted).

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.

Topic Guides ​

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


License ​

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

Released under the MIT License.