Skip to content

About

A lightweight polyfill for Temporal, successor to the JavaScript Date object

Resources

Stars

795 stars

Watchers

10 watching

Forks

Repository files navigation

temporal-polyfill monorepo

Note

πŸŽ‰ temporal-polyfill 1.0 is out! See the 1.0 release notes.

Packages for working with Temporal, the modern successor to the JavaScript Date object πŸ•’

Most projects just need temporal-polyfill; the other packages build on it.

Contents


πŸ“¦ temporal-polyfill

A lightweight polyfill for Temporal. Under 20 kB gzipped and spec-compliant.

npm install temporal-polyfill
import 'temporal-polyfill/global' // most common entrypoint

Temporal.Now.zonedDateTimeISO().toString()
// e.g. '2026-06-18T13:45:00-04:00[America/New_York]'

See the package README for other entrypoints, CDN usage, the expanded-calendar /full/ build, and TypeScript setup.

πŸ“– Read the temporal-polyfill docs β†’


🌳 Tree-shakeable function API

Also shipped inside temporal-polyfill, for library authors and bundle-size-sensitive apps. Every Temporal operation is exposed as a standalone function operating on plain record objects rather than Temporal.* classes, so your bundler keeps only the functions you import.

import * as PlainDateFns from 'temporal-polyfill/fns/PlainDate'

const date = PlainDateFns.create(2026, 6, 1)
const later = PlainDateFns.addMonths(date, 2)

PlainDateFns.toString(later) // '2026-08-01'

Each Temporal type has its own entrypoint under temporal-polyfill/fns/*, such as temporal-polyfill/fns/ZonedDateTime.

πŸ“– Read the tree-shakeable API docs β†’


🧩 For component libraries

Date pickers, schedulers, and other calendar-driven libraries usually end up bundling their own date utility library or asking consumers to configure an adapter.

With the tree-shakeable API, a component library can declare temporal-polyfill as a peer dependency and import only the functions it needs. Host applications decide whether to load the global polyfill (for browsers and runtimes without native Temporal), and because both entrypoints come from the same package, the bundler deduplicates the shared internals:

app
|
β”œβ”€β–Ά temporal-polyfill/global ····┐
|                  (optional)    |
└─▢ <DatePicker>                 β”œβ”€β–Ά one shared copy of internals
     |                           |
     └─▢ temporal-polyfill/fns Β·Β·β”˜
        (only select functions)

Once native Temporal is available in all environments you support, temporal-polyfill-codemod rewrites the function calls to standard Temporal.* code so you can remove the dependency with no lock-in.

πŸ“– Read more: For component authors β†’


πŸ”„ temporal-polyfill-codemod

Automated migrations for temporal-polyfill codebases. The fns-to-temporal transform rewrites code using the tree-shakeable function API into standard Temporal objects and methods.

npx temporal-polyfill-codemod fns-to-temporal <path>
// Before
import * as PlainDateFns from 'temporal-polyfill/fns/PlainDate'
const date = PlainDateFns.create(2024, 5, 1)
const next = PlainDateFns.addDays(date, 3)

// After
const date = new Temporal.PlainDate(2024, 5, 1)
const next = date.add({ days: 3 })

Any usage that cannot be rewritten unambiguously is left unchanged and reported as a diagnostic with a non-zero exit code.

πŸ“– Read the codemod docs β†’


πŸ› οΈ temporal-utils

Convenience helpers for standard Temporal objects (not the tree-shakeable function API), covering common operations that Temporal leaves out: startOfMonth, endOfDay, diffDays, roundToWeek, and similar utilities. Most helpers preserve the input type (PlainDate returns PlainDate, ZonedDateTime returns ZonedDateTime).

npm install temporal-utils
import { startOfMonth, diffDays } from 'temporal-utils'

startOfMonth(Temporal.PlainDate.from('2024-07-20')).toString()
// '2024-07-01'

diffDays(
  Temporal.PlainDate.from('2024-07-01'),
  Temporal.PlainDate.from('2024-07-20'),
)
// 19

temporal-utils works on any standard Temporal instances (native, global polyfill, or local ponyfill import). The examples above assume a global Temporal, such as native Temporal or temporal-polyfill.

πŸ“– Read the temporal-utils docs β†’


πŸ“ temporal-spec

Standalone TypeScript type definitions for Temporal (plus the Temporal additions to Intl and Date), with no runtime code. It is the type layer used by temporal-polyfill and is published separately so other implementations and apps can share the same declarations.

npm install temporal-spec
import type { Temporal } from 'temporal-spec'

function format(zdt: Temporal.ZonedDateTime): string {
  return zdt.toString()
}

Useful on TypeScript < 6.0 (which lacks built-in Temporal types) or when you want namespaced imports without modifying the global scope.

πŸ“– Read the temporal-spec docs β†’

About

A lightweight polyfill for Temporal, successor to the JavaScript Date object

Resources

Stars

795 stars

Watchers

10 watching

Forks

Releases

Packages

Used by

Contributors

Languages