Intl.DateTimeFormat (ESNext)
A spec-compliant polyfill for Intl.DateTimeFormat fully tested by the official ECMAScript Conformance test suite
caution
Right now we only support Gregorian calendar in this polyfill. Therefore we recommend setting calendar: 'gregory'
in your options to be safe.
caution
Right now this polyfill supports daylight transition until 2038 due to Year 2038 problem.
#
Features#
Installation- npm
- yarn
#
RequirementsThis package requires the following capabilities:
#
Usage#
Via polyfill.ioYou can use polyfill.io URL Builder to create a polyfill script tag for Intl.DateTimeFormat
. By default the created URL does not come with any locale data. In order to add locale data, append Intl.DateTimeFormat.~locale.<locale>
, as well as locale data for any required polyfills, to your list of features. For example:
#
Simple#
Dynamic import + capability detection#
Adding IANA Timezone DatabaseWe provide 2 pre-processed IANA Timezone:
#
Full: contains ALL Timezone from IANA database#
Golden: contains popular set of timezones from IANA database#
Default TimezoneSince JS Engines do not expose default timezone, there's currently no way for us to detect local timezone that a browser is in. Therefore, the default timezone in this polyfill is UTC
.
You can change this by either calling __setDefaultTimeZone
or always explicitly pass in timeZone
option for accurate date time calculation.
Since __setDefaultTimeZone
is not in the spec, you should make sure to check for its existence before calling it & after tz data has been loaded, e.g:
#
TestsThis library is fully test262-compliant.