/date-time-format-timezone

Surgically polyfills timezone support in Intl.DateTimeFormat API

Primary LanguageJavaScriptOtherNOASSERTION

Intl.DateTimeFormat timezone polyfill

Surgically polyfills timezone support in Intl.DateTimeFormat API

![Build Status][] ![NPMRel][] [Build Status]: https://travis-ci.org/yahoo/date-time-format-timezone.svg?branch=master [NPMRel]: https://img.shields.io/npm/v/date-time-format-timezone.svg

Some browsers do not support arbitrary time zone in Intl.DateTimeFormat API (becuase its optional as per ECMA-402 standard). This polyfill is only to bring this support. Polyfill contains historical timezone data, CLDR data & tiny code to polyfill this support.

How to use?

  1. install
`npm i date-time-format-timezone`
  1. nodejs
`require('date-time-format-timezone'); // polyfill is ready`
  1. browser
`<script src="build/browserified/date-time-format-time-zone-complete-min.js">`

or

  <script src="build/browserified/date-time-format-time-zone-no-data.js">
  <script src="build/browserified/data/locales/locale-en-US-POSIX.js">
  <script src="build/browserified/data/metazone.js">
  <script src="build/browserified/data/timezones/tzdata-america-los_angeles.js">

This polyfill can add this support.

new Intl.DateTimeFormat('hi', {
    timeZone: 'Asia/Calcutta',
    timeZoneName:'long',
    year: 'numeric',
    month: 'numeric',
    day: 'numeric',
    hour: 'numeric',
    minute: 'numeric',
}).format(new Date());

"११/१/२०१७, पू १:२६ भारतीय मानक समय"


new Intl.DateTimeFormat('en', {
    timeZone: 'America/Los_Angeles',
    timeZoneName:'long',
    year: 'numeric',
    month: 'numeric',
    day: 'numeric',
    hour: 'numeric',
    minute: 'numeric',
}).format(new Date());

"1/10/2017, 12:00 PM Pacific Standard Time"

Support

API Support
Intl.DateTimeFormat
Date.toLocaleString
Date.toLocaleTimeString
Date.toLocaleTimeString

Generate latest data from www.iana.org.

git checkout https://github.com/markandey/DateTimeFormatTimeZone.git
npm install
grunt download
grunt
npm publish

Browserified file size

Minified gzipped
complete 2.64MB 322KB
top zones1 only no locale 369.32KB 71KB
all zones no locale 303.19KB 75KB
top zones1 top locale2 641.86KB 148KB

*1. top zones are custom listed timezones here. *2. top locales are custom listed locales here.

References

  1. http://www.unicode.org/reports/tr35/tr35-dates.html#Using_Time_Zone_Names
  2. http://icu-project.org/apiref/icu4j/com/ibm/icu/text/TimeZoneNames.html