• Stars
    star
    629
  • Rank 69,041 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 4 years ago
  • Updated about 1 year ago

Reviews

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

Repository Details

πŸ•° Simplified, grouped and always up to date list of time zones, with major cities

tzdb GitHub license Tests npm version minizipped size

This is a list and npm package of:

  • "simplified" IANA time zones with their alternative names like Pacific Time instead of America/Los_Angeles, along with major cities for each time zone.
  • all existing raw IANA time zones names
  • "raw" offsets along with current time offsets
  • also includes deprecated time zone names for compatibility

The data and npm packages are automatically updated whenever there are changes to https://www.geonames.org/ which is generated from IANA databases.

This is useful whenever you want to build a time zone select menu in your application.

NPM package

Installation:

npm add @vvo/tzdb

Usage:

import { getTimeZones, rawTimeZones, timeZonesNames, abbreviations } from "@vvo/tzdb";

API

getTimeZones()

const timeZones = getTimeZones();

// You can also provide an optional parameter to include UTC in the result.
// This adds a time zone with the name "UTC" and a fixed offset of 0.
const timeZonesWithUtc = getTimeZones({ includeUtc: true });

This method returns an array of time zones objects:

[
  // ...
  {
    name: "America/Los_Angeles",
    alternativeName: "Pacific Time",
    group: ["America/Los_Angeles"],
    continentCode: "NA",
    continentName: "North America",
    countryName: "United States",
    countryCode: "US",
    mainCities: ["Los Angeles", "San Diego", "San Jose", "San Francisco"],
    rawOffsetInMinutes: -480,
    abbreviation: "PST",
    rawFormat: "-08:00 Pacific Time - Los Angeles, San Diego, San Jose, San Francisco",
    currentTimeOffsetInMinutes: -420, // "current" time zone offset, this is why getTimeZones() is a method and not just an object: it works at runtime
    currentTimeFormat: "-07:00 Pacific Time - Los Angeles, San Diego",
  },
  // ...
];

When relevant, time zones are grouped. The rules for grouping are:

  • if the time zones are in the same country
  • if the DST or summer time offsets are the same
  • if the non-DST, non-summer time offsets are the same
  • then we group the time zones
  • the "main" time zone name (name attribute), is always the one from the most populated city

Here's a grouping example:

{
  name: "America/Dawson_Creek",
  alternativeName: "Mountain Time",
  group: ["America/Creston", "America/Dawson_Creek", "America/Fort_Nelson"],
  continentCode: "NA",
  continentName: "North America",
  countryName: "Canada",
  countryCode: "CA",
  mainCities: ["Fort St. John", "Creston", "Fort Nelson"],
  rawOffsetInMinutes: -420,
  abbreviation: "MST",
  rawFormat: "-07:00 Mountain Time - Fort St. John, Creston, Fort Nelson",
  currentTimeOffsetInMinutes: -420,
  currentTimeFormat: "-07:00 Mountain Time - Fort St. John, Creston"
}

rawTimeZones

This is an array of time zone objects without the current time information:

[
  // ...
  {
    name: "America/Los_Angeles",
    alternativeName: "Pacific Time",
    group: ["America/Los_Angeles"],
    continentCode: "NA",
    continentName: "North America",
    countryName: "United States",
    countryCode: "US",
    mainCities: ["Los Angeles", "San Diego", "San Jose", "San Francisco"],
    rawOffsetInMinutes: -480,
    abbreviation: "PST",
    rawFormat: "-08:00 Pacific Time - Los Angeles, San Diego, San Jose, San Francisco",
  },
  // ...
];

timeZonesNames

This is an array of time zone names:

[
  // ...
  "America/Juneau",
  "America/Kentucky/Louisville",
  "America/Kentucky/Monticello",
  "America/Kralendijk",
  "America/La_Paz",
  "America/Lima",
  "America/Los_Angeles",
  "America/Lower_Princes",
  "America/Maceio",
  "America/Managua",
  "America/Manaus",
  "America/Marigot",
  "America/Martinique",
  "America/Matamoros",
  // ...
];

abbreviations

This is an object mapping timezone abbreviations to their full forms:

{
  // ...
  "Australian Central Daylight Time": "ACDT",
  "Australian Central Standard Time": "ACST",
  "Australian Central Time": "ACT",
  "Australian Central Western Standard Time": "ACWST",
  "Australian Eastern Daylight Time": "AEDT",
  "Australian Eastern Standard Time": "AEST",
  "Australian Eastern Time": "AET",
  "Australian Western Daylight Time": "AWDT",
  "Australian Western Standard Time": "AWST",
  "Azerbaijan Summer Time": "AZST",
  "Azerbaijan Time": "AZT",
  "Azores Summer Time": "AZOST",
  "Azores Time": "AZOT",
  "Bangladesh Standard Time": "BST",
  "Bhutan Time": "BTT",
  "Bolivia Time": "BOT",
  // ...
};

Caution: Although abbreviations can be easy to lookup, they can be misleading. For example: CST can refer to Central Standard Time (-06.00 UTC), China Standard Time (+06.00 UTC) or Cuba Standard Time (-05.00 UTC). And abbreviation full forms don't directly map to any property in the time zone objects returned by rawTimeZones or getTimeZones().

Notes

  • We provide two cities when grouping happens, ranked by population
  • We provide alternative names ("Pacific Time" for "America/Los_Angeles") and remove "Standard", "Daylight" or "Summer" from them
  • If you're using this to build a time zone selector and saving to a database then:
    • make sure to save the name attribute (America/Los_Angeles) in your database
    • when displaying the select with a default value from your database, either select the time zone name that matches, or if the time zone name is part of the group. Example:
const value = timeZones.find((timeZone) => {
  return dbData.timeZone === timeZone.name || timeZone.group.includes(dbData.timeZone);
});

More Repositories

1

gifify

😻 Convert any video file to an optimized animated GIF.
JavaScript
6,088
star
2

iron-session

πŸ›  Secure, stateless, and cookie-based session library for JavaScript
TypeScript
3,276
star
3

lazyload

πŸš… Lazyload images, iframes, widgets with a standalone JavaScript lazyloader
JavaScript
942
star
4

in-viewport

Get a callback when any element becomes visible in a viewport (body or custom viewport)
JavaScript
280
star
5

sourcekarma

Discover how people react to you on GitHub πŸ‘
JavaScript
101
star
6

javascript-library-template

JavaScript library template to focus on ⌨️ coding, πŸ™Œ collaborating and πŸš€ shipping
JavaScript
80
star
7

npm-pkgr

Cache `npm install` results by hashing dependencies
JavaScript
73
star
8

nextjs-vercel-aws-cdk-example

Example Next.js project deployed on Vercel with AWS services for database, cron jobs and asynchronous jobs
JavaScript
70
star
9

docker-selenium-firefox-chrome-beta

A Dockerfile starting a selenium standalone server with Chrome and Firefox beta
Shell
67
star
10

iron-store

🧿 in-memory, signed and encrypted JavaScript store
JavaScript
65
star
11

aws-lambda-nodejs-webpack

Ξ» CDK Construct to build Node.js AWS lambdas using webpack
TypeScript
31
star
12

analytics.js-loader

Asynchronously load segment.com analytics.js with an npm module
JavaScript
29
star
13

concat-files

[DEPRECATED] Concatenate files asynchronously with node.js
JavaScript
26
star
14

zorgs

πŸ¦‘ Command line tool displaying GitHub organizations stats
JavaScript
18
star
15

ansible-archee

dotfiles on steroids
Python
17
star
16

localenvify

localenv and envify combined as a browserify transform
JavaScript
14
star
17

chainit

Turn an asynchronous JavaScript api into an asynchronous chainable JavaScript api
JavaScript
12
star
18

selenium-runner

Run a [url/JSTest, ..] combo in selenium grid, in parallel
JavaScript
10
star
19

mocha-browse

Launch headless browsers on any mocha tests webpage, get results in console
JavaScript
9
star
20

node-whereis

Simply get the first path to a bin on any system
JavaScript
7
star
21

typescript-library-template

TypeScript library template to focus on ⌨️ coding, πŸ™Œ collaborating and πŸš€ shipping
TypeScript
7
star
22

project-name

description
JavaScript
5
star
23

tokenify

🎰 Interactive command line tool to easily get refresh tokens for Spotify API
JavaScript
5
star
24

coronamaison

🎨 All the drawings from the #coronamaison hashtag on Twitter
JavaScript
5
star
25

almanak

WIP Google Calendar like component for React
TypeScript
5
star
26

azure-sb-queue-watcher

Job worker around Azure Service Bus Queues
JavaScript
4
star
27

forkie

Forkie is a graceful process manager for Node.js: start/stop/working?
JavaScript
4
star
28

knex-typescript-migrations-esm

TypeScript
3
star
29

offline-docs

Always get some documentation on the modules you use, even offline
CSS
3
star
30

b64-bench

JavaScript
2
star
31

kcnb1-france.org

Repository for Association KCNB1 France website
PHP
2
star
32

www.berlisco.com

CTRL+W
JavaScript
2
star
33

cron-example

CSS
2
star
34

aws-lambda-nodejs-performance

Example of performance issue of aws-lambda-nodejs
JavaScript
2
star
35

vercel-test-workspaces

JavaScript
1
star
36

test-favicon

Vue
1
star
37

test-post-body

JavaScript
1
star
38

example-empty-project

1
star
39

vvo

1
star
40

npm-test-pre-push

Install a git pre-push hook launching `npm test`
JavaScript
1
star
41

test-babel-node-configuration-file

JavaScript
1
star
42

go-ghoauth

Two steps process for github access_token creation
Go
1
star
43

test-next-broken-packagelock

JavaScript
1
star
44

knex-pool-require-cache-issue

Demo of knex pool issue when combined with delete require.cache
JavaScript
1
star
45

deploy-summary-test

CSS
1
star
46

express-minimal-app

basic express app, production ready
JavaScript
1
star
47

nextjs-jobs

JavaScript
1
star
48

emoshort

Emoji to short name converter
JavaScript
1
star
49

swc-maximum-call-stack-error

TypeScript
1
star
50

test-nextjs-routes-bug-locales

JavaScript
1
star