Socket
Socket
Sign inDemoInstall

date-time-format-timezone

Package Overview
Dependencies
0
Maintainers
4
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    date-time-format-timezone

Surgically polyfills timezone support in Intl.DateTimeFormat API


Version published
Weekly downloads
25K
decreased by-18.21%
Maintainers
4
Install size
23.3 MB
Created
Weekly downloads
 

Readme

Source

Intl.DateTimeFormat timezone polyfill

Surgically polyfills timezone support in Intl.DateTimeFormat API

Build Status NPMRel

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 via nodejs:
npm i date-time-format-timezone

And then import in your code:

require('date-time-format-timezone'); // polyfill is ready
  1. In the browser

include everything:

<script src="https://unpkg.com/date-time-format-timezone@latest/build/browserified/date-time-format-timezone-complete-min.js">

or include individual files:

<script src="https://unpkg.com/date-time-format-timezone@latest/build/browserified/date-time-format-timezone-no-data-min.js">
<script src="https://unpkg.com/date-time-format-timezone@latest/build/browserified/data/locales/locale-en-US-POSIX.js">
<script src="https://unpkg.com/date-time-format-timezone@latest/build/browserified/data/metazone.js">
<script src="https://unpkg.com/date-time-format-timezone@latest/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

APISupport
Intl.DateTimeFormat
Date.toLocaleString
Date.toLocaleTimeString
Date.toLocaleTimeString

Generate latest data from www.iana.org.

git checkout https://github.com/yahoo/date-time-format-timezone.git
npm install
grunt download
grunt
npm publish

Browserified file size

Minifiedgzipped
complete2.64MB322KB
top zones1 only no locale369.32KB71KB
all zones no locale303.19KB75KB
top zones1 top locale2641.86KB148KB

*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

Keywords

FAQs

Last updated on 26 Feb 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc