temporal-polyfill
A spec-compliant* Temporal JavaScript polyfill in 15kb**.
Works in modern browsers***, not Internet Explorer.
Codepen
CDN link
Installation
npm install temporal-polyfill
A) Import globally:
import 'temporal-polyfill/global'
const zdt = Temporal.ZonedDateTime.from('2020-08-05T20:06:13[America/Chicago]')
console.log(zdt.toLocaleString())
B) Import as an ES module without side effects:
import { ZonedDateTime } from 'temporal-polyfill'
const zdt = ZonedDateTime.from('2020-08-05T20:06:13[America/Chicago]')
console.log(zdt.toLocaleString())
C) The above techniques try using the built-in Temporal
object and fall back to the polyfill.
To guarantee using the polyfill, do this:
import { ZonedDateTime } from 'temporal-polyfill/impl'
const zdt = ZonedDateTime.from('2020-08-05T20:06:13[America/Chicago]')
console.log(zdt.toLocaleString())
* = almost spec-compliant.
a few more tests must pass
(see results)
** = the size will shrink as the codebase is cleaned up
*** = targets browsers that support BigInt, however, more browser-compatibility
work is needed