tzdb: Simplified list of time zones and offsets, always up to date, full data included

栏目: IT技术 · 发布时间: 5年前

内容简介:This is a list and npm package of:The data and npm packages areThis is useful whenever you want to build a time zone select menu in your application.

tzdb

This is a list and npm package of:

  • "simplified" IANA time zones and their offset names
  • all existing IANA time zones names
  • and major cities (population > 5,000) with their associated time zones and offset names

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.

Available data

simplified-time-zones.json

This is most probably what you're looking for if you're trying to build a good current time zones selector in your application.

Example data:

{
  "timeZoneName":"America/Anchorage",
  "formatted":"-09:00 Alaska Time - Anchorage, Juneau",
  "group":[
    "America/Anchorage",
    "America/Juneau",
    "America/Metlakatla",
    "America/Nome",
    "America/Sitka",
    "America/Yakutat"
  ]
},
{
  "timeZoneName":"Pacific/Gambier",
  "formatted":"-09:00 Gambier Time - Gambier",
  "group":["Pacific/Gambier"]
},
{
  "timeZoneName":"America/Los_Angeles",
  "formatted":"-08:00 Pacific Time - Los Angeles",
  "group":[
    "America/Los_Angeles"
  ]
},

As you can see, we provide the time zone name and a pre-formatted version using more common offset names.

Notes:

  • Grouping: when two different time zones names are in the same country, same offset and dst rules then we merge them and select the time zone name from the biggest city
  • We provide two cities when grouping happens, ranked by population
  • We provide offset names ("Pacific Time") without dst and remove "Standard" and "Daylight"
  • This can be used to build a good enough (Google calendar like) select box of time zones, but it's your responsibility to handle dst and real offsets

cities-with-time-zones.json

This is a list of major cities (population > 5,000) and their associated time zone information, ranked by population. This is useful if you want to build an application where the user will type a city and you want the time zone information out of it.

Example data:

{
  "geonameId":"5368361",
  "name":"Los Angeles",
  "countryName":"United States",
  "timeZoneName":"America/Los_Angeles",
  "timeZoneOffsetNameWithoutDst":"Pacific Time",
  "population":3971883,
  "modificationDate":"2019-12-12"
},
{
  "geonameId":"1205733",
  "name":"Chittagong",
  "countryName":"Bangladesh",
  "timeZoneName":"Asia/Dhaka",
  "timeZoneOffsetNameWithoutDst":"Bangladesh Time",
  "population":3920222,
  "modificationDate":"2016-11-09"
},
{
  "geonameId":"1804651",
  "name":"Kunming",
  "countryName":"China",
  "timeZoneName":"Asia/Shanghai",
  "timeZoneOffsetNameWithoutDst":"China Time",
  "population":3855346,
  "modificationDate":"2014-08-14"
},
{
  "geonameId":"361058",
  "name":"Alexandria",
  "countryName":"Egypt",
  "timeZoneName":"Africa/Cairo",
  "timeZoneOffsetNameWithoutDst":"Eastern European Time",
  "population":3811516,
  "modificationDate":"2019-09-05"
},

time-zones-names.json

This is the raw list of all IANA time zones ranked by alphabetical order.

Example data:

"America/La_Paz",
"America/Lima",
"America/Los_Angeles",
"America/Lower_Princes",
"America/Maceio",
"America/Managua",
"America/Manaus",
"America/Marigot",
"America/Martinique",

NPM package

Installation:

npm add @vvo/tzdb

Usage:

import cities from "@vvo/tzdb/cities-with-time-zones.json";
import simplifiedTimeZones from "@vvo/tzdb/simplified-time-zones.json";
import timeZones from "@vvo/tzdb/time-zones-names.json";

Algolia

You can store cities information on a search engine like Algolia . There's a yarn build command you can use if you clone this repository to create your own Algolia index. The expected environment variables are:

ALGOLIA_APPLICATION_ID=... ALGOLIA_ADMIN_API_KEY=... ALGOLIA_INDEX_NAME=... yarn build

Here's a demo of the index:

tzdb: Simplified list of time zones and offsets, always up to date, full data included


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

数据之巅

数据之巅

涂子沛 / 中信出版社 / 2014-5-1 / 65.00元

《数据之巅:大数据革命,历史、现实与未来》从美国建国之基讲起,通过阐述初数时代、内战时代、镀金时代、进步时代、抽样时代、大数据时代的特征,系统梳理了美国数据文化的形成,阐述了其数据治国之道,论述了中国数据文化的薄弱之处,展望了未来数据世界的远景。 “尊重事实,用数据说话”,“推崇知识和理性,用数据创新”,作者不仅意在传承黄仁宇“数目字”管理的薪火,还试图把数据这个科技符号在中国转变为文化符号......一起来看看 《数据之巅》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

URL 编码/解码
URL 编码/解码

URL 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器