• This repository has been archived on 27/Jun/2020
  • Stars
    star
    108
  • Rank 321,259 (Top 7 %)
  • Language
    JavaScript
  • License
    Other
  • Created almost 8 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Surgically polyfills timezone support in Intl.DateTimeFormat API

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

API Support
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

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

More Repositories

1

formatjs

The monorepo home to all of the FormatJS related libraries, most notably react-intl.
TypeScript
14,283
star
2

intl-messageformat

[MIGRATED] Format a string with placeholders, including plural and select support to create localized messages.
TypeScript
530
star
3

babel-plugin-react-intl

Extracts string messages from React components that use React Intl.
JavaScript
420
star
4

formatjs-site

Documentation for client/server internationalization in JavaScript.
HTML
315
star
5

handlebars-intl

Handlebars helpers for internationalization.
JavaScript
265
star
6

intl-relativeformat

Formats JavaScript dates to relative time strings (e.g., "3 hours ago").
TypeScript
213
star
7

formatjs-old

The monorepo home to all of the FormatJS related libraries.
TypeScript
156
star
8

intl-messageformat-parser

[MIGRATED] Parses ICU message strings to an AST that can be used to format the messages for a person's locale.
JavaScript
115
star
9

intl-locales-supported

[MIGRATED] Utility to help you polyfill the Node.js runtime when the Intl APIs are missing, or if the built-in Intl is missing locale data that you need.
JavaScript
67
star
10

intl-format-cache

Produces instances of JavaScript `Intl` formats, and caches them for reuse.
TypeScript
55
star
11

dust-intl

Dust helpers for internationalization.
JavaScript
48
star
12

js-module-formats

Detect different types of javascript modules formats
JavaScript
13
star
13

input-data-formatter

JavaScript
11
star
14

formatjs-extract-cldr-data

[MIGRATED] Utility library that extracts the CLDR data that's needed by the FormatJS libraries.
JavaScript
11
star
15

grunt-extract-cldr-data

Extract CLDR data and transform it for use in JavaScript.
JavaScript
7
star
16

broccoli-js-module-formats

Broccoli plugin for obtaining files that use a particular module system
JavaScript
2
star
17

formatjs.github.io

Website for formatjs.io
JavaScript
1
star