Skip to content

rkodey/temporal-extended

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Temporal Extended (WIP)

The extended object way

import  'temporal-extended';

const now = Temporal.Now.zonedDateTimeISO();
now.format('YYYY-MM-DD');             // 2026-06-01
now.strftime('%Y-%m-%d');             // 2026-06-01
now.strftime('Today is: %A');         // Today is: Monday

const tomorrow = now.add({ days: 1 });
now.isBefore(tomorrow);               // true
now.isAfter(tomorrow);                // false

The tree-shakable way

import    format              from  'temporal-extended/format';
import    strftime            from  'temporal-extended/strftime';
import  { isBefore, isAfter } from  'temporal-extended/compare';

const now = Temporal.Now.zonedDateTimeISO();
format(now, 'YYYY-MM-DD');            // 2026-06-01
strftime(now, '%Y-%m-%d');            // 2026-06-01
strftime(now, 'Today is: %A');        // Today is: Monday

const tomorrow = now.add({ days: 1 });
isBefore(now, tomorrow);              // true
isAfter(now, tomorrow);               // false

The full-functional way

import  * as TemporalEx       from  'temporal-extended/functional';

TemporalEx.parse('2026-06-01').format('YYYY-MM'); // 2026-06

Choose either interface, or use both:

  1. Extend the Temporal date objects for a convenient highly readable interface.
  2. Import individual ( tree-shakable? ) functions while leaving the Temporal objects unmodified.

Why do we need Temporal Extended?

The new JavaScript Temporal API replacement for Date() is pretty nice. It's very precise in its definition, which also makes it very verbose. I happen to like it that way.

While the proposed ( practically official ) API is very thorough and well designed, apparently the committee assumed no one would ever need to output Temporal data to a user interface.

You see, there are these beings called Product Managers... And they like to design user interfaces that don't necessarily conform to ISO spec.

So yeah... We need a general purpose string formatter.


Is Temporal Extended safe?

  • No automated CI/CD.
  • No runtime dependencies. No supply-chain exposure.
  • Temporal object extensions are purely additive and do not alter existing behavior.
  • But if you're paranoid, you can use the functional interface!

Provided Functions

Formatters and parsers

  • strftime : the venerable formatter from C
  • format : from dayjs / moment.js
  • parse : from dayjs

Quality-of-Life Helpers

  • isBefore
  • isAfter
  • isBetween
  • ... more to come

@TODO

  • Add extended formats from moment.js into format
  • Add a unicode formatter to match date-fns
  • Add more optional helper function
  • Add custom parser, based on either regex or format tokens, maybe both

About

Extend the JS Temporal Date API to include custom string formatting, parsing, and quality-of-life helper functions

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors