forked from vvo/tzdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-abbreviations.js
68 lines (61 loc) · 1.81 KB
/
generate-abbreviations.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import fs from "fs";
import path from "path";
import got from "got";
import * as cheerio from "cheerio";
import sortKeys from "sort-keys";
async function run() {
const { body: abbreviationsData } = await got(
"https://www.timeanddate.com/time/zones/",
);
const customAbbreviations = {
"East Africa Time": "EAT",
"Hawaii-Aleutian Time": "HAST",
"Brasilia Time": "BRT",
"Yukon Time": "YT",
"Venezuela Time": "VET",
"St. Pierre & Miquelon Time": "PM",
"Dumont-d’Urville Time": "DDUT",
"Arabian Time": "AST",
"East Kazakhstan Time": "ALMT",
"West Kazakhstan Time": "AQTT",
"Petropavlovsk-Kamchatski Time": "PETT",
"Western Indonesia Time": "WIB",
"Central Indonesia Time": "WITA",
"Eastern Indonesia Time": "WIT",
"Korean Time": "KST",
"Taipei Time": "TWT",
"Falkland Islands Time": "FKST",
"Indian Ocean Time": "IOT",
"French Southern & Antarctic Time": "FSAT",
"Réunion Time": "RET",
"Apia Time": "WST",
"Chatham Time": "CHAST",
"Phoenix Islands Time": "PHOT",
"Gilbert Islands Time": "GILT",
"Wake Island Time": "WAKT",
"Norfolk Island Time": "NFT",
"Cook Islands Time": "CKT",
"Wallis & Futuna Time": "WFT",
};
const $ = cheerio.load(abbreviationsData);
const abbreviations = $("#tz-abb tbody tr")
.toArray()
.reduce((acc, row) => {
const abbreviation = $(row.children[0]).text().trim();
const longForm = $(row.children[1].children[0]).text().trim();
acc[longForm] = abbreviation;
return acc;
}, {});
fs.writeFileSync(
path.join(__dirname, "abbreviations.json"),
JSON.stringify(
sortKeys({ ...abbreviations, ...customAbbreviations }),
null,
2,
).replace(/}/g, "}\n"),
);
}
run().catch((error) => {
console.error(error);
process.exit(1);
});