@vvo/tzdb 6.198.0 → 6.199.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -415,4 +415,4 @@
415
415
  "Pacific/Tarawa",
416
416
  "Pacific/Tongatapu",
417
417
  "Pacific/Wake",
418
- "Pacific/Wallis"]
418
+ "Pacific/Wallis"]
@@ -1,26 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = format;
7
- function format({
8
- alternativeName,
9
- mainCities,
10
- rawOffsetInMinutes,
11
- currentTimeOffsetInMinutes
12
- }, {
13
- useCurrentOffset = false
14
- } = {}) {
15
- const offsetInHours = useCurrentOffset ? getOffsetString(currentTimeOffsetInMinutes) : getOffsetString(rawOffsetInMinutes);
16
- return `${offsetInHours.padStart(6, "+")} ${alternativeName} - ${mainCities.join(", ")}`;
17
- }
18
- function getOffsetString(offsetInMinutes) {
19
- const absOffsetInMinutes = Math.abs(offsetInMinutes);
20
- const [hours, minutes] = [Math.floor(absOffsetInMinutes / 60), absOffsetInMinutes % 60].map(v => {
21
- return v.toString().padStart(2, "0");
22
- });
23
- const durationInHoursMinutes = `${hours}:${minutes}`;
24
- return `${offsetInMinutes >= 0 ? "+" : "-"}${durationInHoursMinutes}`;
25
- }
26
- //# sourceMappingURL=formatTimeZone.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"formatTimeZone.js","names":["format","alternativeName","mainCities","rawOffsetInMinutes","currentTimeOffsetInMinutes","useCurrentOffset","offsetInHours","getOffsetString","padStart","join","offsetInMinutes","absOffsetInMinutes","Math","abs","hours","minutes","floor","map","v","toString","durationInHoursMinutes"],"sources":["../lib/formatTimeZone.js"],"sourcesContent":["export default function format(\n {\n alternativeName,\n mainCities,\n rawOffsetInMinutes,\n currentTimeOffsetInMinutes,\n },\n { useCurrentOffset = false } = {},\n) {\n const offsetInHours = useCurrentOffset\n ? getOffsetString(currentTimeOffsetInMinutes)\n : getOffsetString(rawOffsetInMinutes);\n\n return `${offsetInHours.padStart(\n 6,\n \"+\",\n )} ${alternativeName} - ${mainCities.join(\", \")}`;\n}\n\nfunction getOffsetString(offsetInMinutes) {\n const absOffsetInMinutes = Math.abs(offsetInMinutes);\n const [hours, minutes] = [\n Math.floor(absOffsetInMinutes / 60),\n absOffsetInMinutes % 60,\n ].map((v) => {\n return v.toString().padStart(2, \"0\");\n });\n const durationInHoursMinutes = `${hours}:${minutes}`;\n\n return `${offsetInMinutes >= 0 ? \"+\" : \"-\"}${durationInHoursMinutes}`;\n}\n"],"mappings":";;;;;;AAAe,SAASA,MAAMA,CAC5B;EACEC,eAAe;EACfC,UAAU;EACVC,kBAAkB;EAClBC;AACF,CAAC,EACD;EAAEC,gBAAgB,GAAG;AAAM,CAAC,GAAG,CAAC,CAAC,EACjC;EACA,MAAMC,aAAa,GAAGD,gBAAgB,GAClCE,eAAe,CAACH,0BAA0B,CAAC,GAC3CG,eAAe,CAACJ,kBAAkB,CAAC;EAEvC,OAAO,GAAGG,aAAa,CAACE,QAAQ,CAC9B,CAAC,EACD,GACF,CAAC,IAAIP,eAAe,MAAMC,UAAU,CAACO,IAAI,CAAC,IAAI,CAAC,EAAE;AACnD;AAEA,SAASF,eAAeA,CAACG,eAAe,EAAE;EACxC,MAAMC,kBAAkB,GAAGC,IAAI,CAACC,GAAG,CAACH,eAAe,CAAC;EACpD,MAAM,CAACI,KAAK,EAAEC,OAAO,CAAC,GAAG,CACvBH,IAAI,CAACI,KAAK,CAACL,kBAAkB,GAAG,EAAE,CAAC,EACnCA,kBAAkB,GAAG,EAAE,CACxB,CAACM,GAAG,CAAEC,CAAC,IAAK;IACX,OAAOA,CAAC,CAACC,QAAQ,CAAC,CAAC,CAACX,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC;EACtC,CAAC,CAAC;EACF,MAAMY,sBAAsB,GAAG,GAAGN,KAAK,IAAIC,OAAO,EAAE;EAEpD,OAAO,GAAGL,eAAe,IAAI,CAAC,GAAG,GAAG,GAAG,GAAG,GAAGU,sBAAsB,EAAE;AACvE","ignoreList":[]}
@@ -1,62 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = getTimeZones;
7
- var _rawTimeZones = _interopRequireDefault(require("../raw-time-zones.json"));
8
- var _formatTimeZone = _interopRequireDefault(require("./formatTimeZone.js"));
9
- var _timeZone = require("./utils/timeZone.js");
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- function getTimeZones(opts) {
12
- const includeUtc = !!opts && opts.includeUtc;
13
- return _rawTimeZones.default.reduce(function (acc, timeZone) {
14
- const timeZoneName = timeZone.name;
15
- const currentOffset = (0, _timeZone.getZoneOffset)(timeZoneName);
16
-
17
- // We build on the latest Node.js version, Node.js embed IANA databases
18
- // it might happen that the environment that will execute getTimeZones() will not know about some
19
- // timezones. So we ignore the timezone at runtim
20
- // See https://github.com/vvo/tzdb/issues/43
21
- if (currentOffset === false) {
22
- return acc;
23
- }
24
- const timeZoneWithCurrentTimeData = {
25
- ...timeZone,
26
- currentTimeOffsetInMinutes: currentOffset
27
- };
28
- acc.push({
29
- ...timeZoneWithCurrentTimeData,
30
- currentTimeFormat: (0, _formatTimeZone.default)(timeZoneWithCurrentTimeData, {
31
- useCurrentOffset: true
32
- })
33
- });
34
- return acc;
35
- }, includeUtc ? [utcTimezone] : []).sort((a, b) => {
36
- return compareNumbers(a, b) || compareStrings(a.alternativeName, b.alternativeName) || compareStrings(a.mainCities[0], b.mainCities[0]);
37
- });
38
- }
39
- function compareNumbers(x, y) {
40
- return x.currentTimeOffsetInMinutes - y.currentTimeOffsetInMinutes;
41
- }
42
- function compareStrings(x, y) {
43
- if (typeof x === "string" && typeof y === "string") {
44
- return x.localeCompare(y);
45
- }
46
- return 0;
47
- }
48
- const utcTimezone = {
49
- name: "Etc/UTC",
50
- alternativeName: "Coordinated Universal Time (UTC)",
51
- abbreviation: "UTC",
52
- group: ["Etc/UTC", "Etc/UCT", "UCT", "UTC", "Universal", "Zulu"],
53
- countryName: "",
54
- continentCode: "",
55
- continentName: "",
56
- mainCities: [""],
57
- rawOffsetInMinutes: 0,
58
- rawFormat: "+00:00 Coordinated Universal Time (UTC)",
59
- currentTimeOffsetInMinutes: 0,
60
- currentTimeFormat: "+00:00 Coordinated Universal Time (UTC)"
61
- };
62
- //# sourceMappingURL=getTimeZones.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getTimeZones.js","names":["_rawTimeZones","_interopRequireDefault","require","_formatTimeZone","_timeZone","e","__esModule","default","getTimeZones","opts","includeUtc","rawTimeZones","reduce","acc","timeZone","timeZoneName","name","currentOffset","getZoneOffset","timeZoneWithCurrentTimeData","currentTimeOffsetInMinutes","push","currentTimeFormat","formatTimeZone","useCurrentOffset","utcTimezone","sort","a","b","compareNumbers","compareStrings","alternativeName","mainCities","x","y","localeCompare","abbreviation","group","countryName","continentCode","continentName","rawOffsetInMinutes","rawFormat"],"sources":["../lib/getTimeZones.js"],"sourcesContent":["import rawTimeZones from \"../raw-time-zones.json\";\n\nimport formatTimeZone from \"./formatTimeZone.js\";\nimport { getZoneOffset } from \"./utils/timeZone.js\";\n\nexport default function getTimeZones(opts) {\n const includeUtc = !!opts && opts.includeUtc;\n return rawTimeZones\n .reduce(\n function (acc, timeZone) {\n const timeZoneName = timeZone.name;\n const currentOffset = getZoneOffset(timeZoneName);\n\n // We build on the latest Node.js version, Node.js embed IANA databases\n // it might happen that the environment that will execute getTimeZones() will not know about some\n // timezones. So we ignore the timezone at runtim\n // See https://github.com/vvo/tzdb/issues/43\n if (currentOffset === false) {\n return acc;\n }\n\n const timeZoneWithCurrentTimeData = {\n ...timeZone,\n currentTimeOffsetInMinutes: currentOffset,\n };\n\n acc.push({\n ...timeZoneWithCurrentTimeData,\n currentTimeFormat: formatTimeZone(timeZoneWithCurrentTimeData, {\n useCurrentOffset: true,\n }),\n });\n\n return acc;\n },\n includeUtc ? [utcTimezone] : [],\n )\n .sort((a, b) => {\n return (\n compareNumbers(a, b) ||\n compareStrings(a.alternativeName, b.alternativeName) ||\n compareStrings(a.mainCities[0], b.mainCities[0])\n );\n });\n}\n\nfunction compareNumbers(x, y) {\n return x.currentTimeOffsetInMinutes - y.currentTimeOffsetInMinutes;\n}\n\nfunction compareStrings(x, y) {\n if (typeof x === \"string\" && typeof y === \"string\") {\n return x.localeCompare(y);\n }\n return 0;\n}\n\nconst utcTimezone = {\n name: \"Etc/UTC\",\n alternativeName: \"Coordinated Universal Time (UTC)\",\n abbreviation: \"UTC\",\n group: [\"Etc/UTC\", \"Etc/UCT\", \"UCT\", \"UTC\", \"Universal\", \"Zulu\"],\n countryName: \"\",\n continentCode: \"\",\n continentName: \"\",\n mainCities: [\"\"],\n rawOffsetInMinutes: 0,\n rawFormat: \"+00:00 Coordinated Universal Time (UTC)\",\n currentTimeOffsetInMinutes: 0,\n currentTimeFormat: \"+00:00 Coordinated Universal Time (UTC)\",\n};\n"],"mappings":";;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,eAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAAoD,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAErC,SAASG,YAAYA,CAACC,IAAI,EAAE;EACzC,MAAMC,UAAU,GAAG,CAAC,CAACD,IAAI,IAAIA,IAAI,CAACC,UAAU;EAC5C,OAAOC,qBAAY,CAChBC,MAAM,CACL,UAAUC,GAAG,EAAEC,QAAQ,EAAE;IACvB,MAAMC,YAAY,GAAGD,QAAQ,CAACE,IAAI;IAClC,MAAMC,aAAa,GAAG,IAAAC,uBAAa,EAACH,YAAY,CAAC;;IAEjD;IACA;IACA;IACA;IACA,IAAIE,aAAa,KAAK,KAAK,EAAE;MAC3B,OAAOJ,GAAG;IAC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E;EACjBR,UAAU,EAAE,CAAC,EAAE,CAAC;EAChBS,kBAAkB,EAAE,CAAC;EACrBC,SAAS,EAAE,yCAAyC;EACpDtB,0BAA0B,EAAE,CAAC;EAC7BE,iBAAiB,EAAE;AACrB,CAAC","ignoreList":[]}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["_rawTimeZones","_interopRequireDefault","require","_timeZonesNames","_getTimeZones","_abbreviations","e","__esModule","default"],"sources":["../lib/index.js"],"sourcesContent":["export { default as rawTimeZones } from \"../raw-time-zones.json\";\nexport { default as timeZonesNames } from \"../time-zones-names.json\";\nexport { default as getTimeZones } from \"./getTimeZones.js\";\nexport { default as abbreviations } from \"../abbreviations.json\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,eAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,aAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,cAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAAiE,SAAAD,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
@@ -1,99 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getZoneOffset = getZoneOffset;
7
- // Most of the code here is from Luxon
8
- // Copyright 2019 JS Foundation and other contributors
9
-
10
- // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11
-
12
- // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
-
14
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
-
16
- const ianaRegex = /^[A-Za-z_+-]{1,256}(:?\/[A-Za-z_+-]{1,256}(\/[A-Za-z_+-]{1,256})?)?$/;
17
- const typeToPos = {
18
- year: 0,
19
- month: 1,
20
- day: 2,
21
- hour: 3,
22
- minute: 4,
23
- second: 5
24
- };
25
- function isValidIanaSpecifier(s) {
26
- return !!(s && s.match(ianaRegex));
27
- }
28
- function hackyOffset(dtf, date) {
29
- const formatted = dtf.format(date).replace(/\u200E/g, "");
30
- const parsed = /(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(formatted);
31
- const [, fMonth, fDay, fYear, fHour, fMinute, fSecond] = parsed;
32
- return [fYear, fMonth, fDay, fHour, fMinute, fSecond];
33
- }
34
- function partsOffset(dtf, date) {
35
- const formatted = dtf.formatToParts(date);
36
- const filled = [];
37
- for (let i = 0; i < formatted.length; i++) {
38
- const {
39
- type,
40
- value
41
- } = formatted[i];
42
- const pos = typeToPos[type];
43
- if (typeof pos !== "undefined") {
44
- filled[pos] = parseInt(value, 10);
45
- }
46
- }
47
- return filled;
48
- }
49
- function makeDTF(zone) {
50
- return new Intl.DateTimeFormat("en-US", {
51
- hourCycle: "h23",
52
- timeZone: zone,
53
- year: "numeric",
54
- month: "2-digit",
55
- day: "2-digit",
56
- hour: "2-digit",
57
- minute: "2-digit",
58
- second: "2-digit"
59
- });
60
- }
61
-
62
- // covert a calendar object to a local timestamp (epoch, but with the offset baked in)
63
- function objToLocalTS(obj) {
64
- let d = Date.UTC(obj.year, obj.month - 1, obj.day, obj.hour, obj.minute, obj.second, obj.millisecond);
65
-
66
- // for legacy reasons, years between 0 and 99 are interpreted as 19XX; revert that
67
- if (obj.year < 100 && obj.year >= 0) {
68
- d = new Date(d);
69
- d.setUTCFullYear(d.getUTCFullYear() - 1900);
70
- }
71
- return +d;
72
- }
73
- function getZoneOffset(timeZoneName) {
74
- if (!isValidIanaSpecifier(timeZoneName)) {
75
- return false;
76
- }
77
- const date = new Date(Date.now());
78
- let dtf;
79
- try {
80
- dtf = makeDTF(timeZoneName);
81
- } catch (_) {
82
- return false;
83
- }
84
- const [year, month, day, hour, minute, second] = dtf.formatToParts ? partsOffset(dtf, date) : hackyOffset(dtf, date);
85
- const asUTC = objToLocalTS({
86
- year,
87
- month,
88
- day,
89
- hour,
90
- minute,
91
- second,
92
- millisecond: 0
93
- });
94
- let asTS = +date;
95
- const over = asTS % 1000;
96
- asTS -= over >= 0 ? over : 1000 + over;
97
- return (asUTC - asTS) / (60 * 1000);
98
- }
99
- //# sourceMappingURL=timeZone.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"timeZone.js","names":["ianaRegex","typeToPos","year","month","day","hour","minute","second","isValidIanaSpecifier","s","match","hackyOffset","dtf","date","formatted","format","replace","parsed","exec","fMonth","fDay","fYear","fHour","fMinute","fSecond","partsOffset","formatToParts","filled","i","length","type","value","pos","parseInt","makeDTF","zone","Intl","DateTimeFormat","hourCycle","timeZone","objToLocalTS","obj","d","Date","UTC","millisecond","setUTCFullYear","getUTCFullYear","getZoneOffset","timeZoneName","now","_","asUTC","asTS","over"],"sources":["../../lib/utils/timeZone.js"],"sourcesContent":["// Most of the code here is from Luxon\n// Copyright 2019 JS Foundation and other contributors\n\n// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\n// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nconst ianaRegex =\n /^[A-Za-z_+-]{1,256}(:?\\/[A-Za-z_+-]{1,256}(\\/[A-Za-z_+-]{1,256})?)?$/;\n\nconst typeToPos = {\n year: 0,\n month: 1,\n day: 2,\n hour: 3,\n minute: 4,\n second: 5,\n};\n\nfunction isValidIanaSpecifier(s) {\n return !!(s && s.match(ianaRegex));\n}\n\nfunction hackyOffset(dtf, date) {\n const formatted = dtf.format(date).replace(/\\u200E/g, \"\");\n const parsed = /(\\d+)\\/(\\d+)\\/(\\d+),? (\\d+):(\\d+):(\\d+)/.exec(formatted);\n const [, fMonth, fDay, fYear, fHour, fMinute, fSecond] = parsed;\n return [fYear, fMonth, fDay, fHour, fMinute, fSecond];\n}\n\nfunction partsOffset(dtf, date) {\n const formatted = dtf.formatToParts(date);\n const filled = [];\n for (let i = 0; i < formatted.length; i++) {\n const { type, value } = formatted[i];\n const pos = typeToPos[type];\n\n if (typeof pos !== \"undefined\") {\n filled[pos] = parseInt(value, 10);\n }\n }\n return filled;\n}\n\nfunction makeDTF(zone) {\n return new Intl.DateTimeFormat(\"en-US\", {\n hourCycle: \"h23\",\n timeZone: zone,\n year: \"numeric\",\n month: \"2-digit\",\n day: \"2-digit\",\n hour: \"2-digit\",\n minute: \"2-digit\",\n second: \"2-digit\",\n });\n}\n\n// covert a calendar object to a local timestamp (epoch, but with the offset baked in)\nfunction objToLocalTS(obj) {\n let d = Date.UTC(\n obj.year,\n obj.month - 1,\n obj.day,\n obj.hour,\n obj.minute,\n obj.second,\n obj.millisecond,\n );\n\n // for legacy reasons, years between 0 and 99 are interpreted as 19XX; revert that\n if (obj.year < 100 && obj.year >= 0) {\n d = new Date(d);\n d.setUTCFullYear(d.getUTCFullYear() - 1900);\n }\n return +d;\n}\n\nexport function getZoneOffset(timeZoneName) {\n if (!isValidIanaSpecifier(timeZoneName)) {\n return false;\n }\n\n const date = new Date(Date.now());\n\n let dtf;\n\n try {\n dtf = makeDTF(timeZoneName);\n } catch (_) {\n return false;\n }\n\n const [year, month, day, hour, minute, second] = dtf.formatToParts\n ? partsOffset(dtf, date)\n : hackyOffset(dtf, date);\n\n const asUTC = objToLocalTS({\n year,\n month,\n day,\n hour,\n minute,\n second,\n millisecond: 0,\n });\n\n let asTS = +date;\n const over = asTS % 1000;\n asTS -= over >= 0 ? over : 1000 + over;\n return (asUTC - asTS) / (60 * 1000);\n}\n"],"mappings":";;;;;;AAAA;AACA;;AAEA;;AAEA;;AAEA;;AAEA,MAAMA,SAAS,GACb,sEAAsE;AAExE,MAAMC,SAAS,GAAG;EAChBC,IAAI,EAAE,CAAC;EACPC,KAAK,EAAE,CAAC;EACRC,GAAG,EAAE,CAAC;EACNC,IAAI,EAAE,CAAC;EACPC,MAAM,EAAE,CAAC;EACTC,MAAM,EAAE;AACV,CAAC;AAED,SAASC,oBAAoBA,CAACC,CAAC,EAAE;EAC/B,OAAO,CAAC,EAAEA,CAAC,IAAIA,CAAC,CAACC,KAAK,CAACV,SAAS,CAAC,CAAC;AACpC;AAEA,SAASW,WAAWA,CAACC,GAAG,EAAEC,IAAI,EAAE;EAC9B,MAAMC,SAAS,GAAGF,GAAG,CAACG,MAAM,CAACF,IAAI,CAAC,CAACG,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;EACzD,MAAMC,MAAM,G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I,IAAI,CAAC,GAAGA,IAAI,GAAG,IAAI,GAAGA,IAAI;EACtC,OAAO,CAACF,KAAK,GAAGC,IAAI,KAAK,EAAE,GAAG,IAAI,CAAC;AACrC","ignoreList":[]}
package/index.d.ts DELETED
@@ -1,28 +0,0 @@
1
- type TimeZoneName = string;
2
-
3
- interface RawTimeZone {
4
- name: TimeZoneName;
5
- alternativeName: string;
6
- group: string[];
7
- continentCode: string;
8
- continentName: string;
9
- countryName: string;
10
- countryCode: string;
11
- mainCities: string[];
12
- rawOffsetInMinutes: number;
13
- abbreviation: string;
14
- rawFormat: string;
15
- }
16
-
17
- interface TimeZone extends RawTimeZone {
18
- currentTimeOffsetInMinutes: number;
19
- currentTimeFormat: string;
20
- }
21
-
22
- interface TimeZoneOptions {
23
- includeUtc?: boolean;
24
- }
25
-
26
- export const rawTimeZones: RawTimeZone[];
27
- export const timeZonesNames: TimeZoneName[];
28
- export function getTimeZones(opts?: TimeZoneOptions): TimeZone[];
@@ -1,31 +0,0 @@
1
- export default function format(
2
- {
3
- alternativeName,
4
- mainCities,
5
- rawOffsetInMinutes,
6
- currentTimeOffsetInMinutes,
7
- },
8
- { useCurrentOffset = false } = {},
9
- ) {
10
- const offsetInHours = useCurrentOffset
11
- ? getOffsetString(currentTimeOffsetInMinutes)
12
- : getOffsetString(rawOffsetInMinutes);
13
-
14
- return `${offsetInHours.padStart(
15
- 6,
16
- "+",
17
- )} ${alternativeName} - ${mainCities.join(", ")}`;
18
- }
19
-
20
- function getOffsetString(offsetInMinutes) {
21
- const absOffsetInMinutes = Math.abs(offsetInMinutes);
22
- const [hours, minutes] = [
23
- Math.floor(absOffsetInMinutes / 60),
24
- absOffsetInMinutes % 60,
25
- ].map((v) => {
26
- return v.toString().padStart(2, "0");
27
- });
28
- const durationInHoursMinutes = `${hours}:${minutes}`;
29
-
30
- return `${offsetInMinutes >= 0 ? "+" : "-"}${durationInHoursMinutes}`;
31
- }
@@ -1,71 +0,0 @@
1
- import rawTimeZones from "../raw-time-zones.json";
2
-
3
- import formatTimeZone from "./formatTimeZone.js";
4
- import { getZoneOffset } from "./utils/timeZone.js";
5
-
6
- export default function getTimeZones(opts) {
7
- const includeUtc = !!opts && opts.includeUtc;
8
- return rawTimeZones
9
- .reduce(
10
- function (acc, timeZone) {
11
- const timeZoneName = timeZone.name;
12
- const currentOffset = getZoneOffset(timeZoneName);
13
-
14
- // We build on the latest Node.js version, Node.js embed IANA databases
15
- // it might happen that the environment that will execute getTimeZones() will not know about some
16
- // timezones. So we ignore the timezone at runtim
17
- // See https://github.com/vvo/tzdb/issues/43
18
- if (currentOffset === false) {
19
- return acc;
20
- }
21
-
22
- const timeZoneWithCurrentTimeData = {
23
- ...timeZone,
24
- currentTimeOffsetInMinutes: currentOffset,
25
- };
26
-
27
- acc.push({
28
- ...timeZoneWithCurrentTimeData,
29
- currentTimeFormat: formatTimeZone(timeZoneWithCurrentTimeData, {
30
- useCurrentOffset: true,
31
- }),
32
- });
33
-
34
- return acc;
35
- },
36
- includeUtc ? [utcTimezone] : [],
37
- )
38
- .sort((a, b) => {
39
- return (
40
- compareNumbers(a, b) ||
41
- compareStrings(a.alternativeName, b.alternativeName) ||
42
- compareStrings(a.mainCities[0], b.mainCities[0])
43
- );
44
- });
45
- }
46
-
47
- function compareNumbers(x, y) {
48
- return x.currentTimeOffsetInMinutes - y.currentTimeOffsetInMinutes;
49
- }
50
-
51
- function compareStrings(x, y) {
52
- if (typeof x === "string" && typeof y === "string") {
53
- return x.localeCompare(y);
54
- }
55
- return 0;
56
- }
57
-
58
- const utcTimezone = {
59
- name: "Etc/UTC",
60
- alternativeName: "Coordinated Universal Time (UTC)",
61
- abbreviation: "UTC",
62
- group: ["Etc/UTC", "Etc/UCT", "UCT", "UTC", "Universal", "Zulu"],
63
- countryName: "",
64
- continentCode: "",
65
- continentName: "",
66
- mainCities: [""],
67
- rawOffsetInMinutes: 0,
68
- rawFormat: "+00:00 Coordinated Universal Time (UTC)",
69
- currentTimeOffsetInMinutes: 0,
70
- currentTimeFormat: "+00:00 Coordinated Universal Time (UTC)",
71
- };
package/lib/index.js DELETED
@@ -1,4 +0,0 @@
1
- export { default as rawTimeZones } from "../raw-time-zones.json";
2
- export { default as timeZonesNames } from "../time-zones-names.json";
3
- export { default as getTimeZones } from "./getTimeZones.js";
4
- export { default as abbreviations } from "../abbreviations.json";
@@ -1,113 +0,0 @@
1
- // Most of the code here is from Luxon
2
- // Copyright 2019 JS Foundation and other contributors
3
-
4
- // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
-
6
- // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
-
8
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
-
10
- const ianaRegex =
11
- /^[A-Za-z_+-]{1,256}(:?\/[A-Za-z_+-]{1,256}(\/[A-Za-z_+-]{1,256})?)?$/;
12
-
13
- const typeToPos = {
14
- year: 0,
15
- month: 1,
16
- day: 2,
17
- hour: 3,
18
- minute: 4,
19
- second: 5,
20
- };
21
-
22
- function isValidIanaSpecifier(s) {
23
- return !!(s && s.match(ianaRegex));
24
- }
25
-
26
- function hackyOffset(dtf, date) {
27
- const formatted = dtf.format(date).replace(/\u200E/g, "");
28
- const parsed = /(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(formatted);
29
- const [, fMonth, fDay, fYear, fHour, fMinute, fSecond] = parsed;
30
- return [fYear, fMonth, fDay, fHour, fMinute, fSecond];
31
- }
32
-
33
- function partsOffset(dtf, date) {
34
- const formatted = dtf.formatToParts(date);
35
- const filled = [];
36
- for (let i = 0; i < formatted.length; i++) {
37
- const { type, value } = formatted[i];
38
- const pos = typeToPos[type];
39
-
40
- if (typeof pos !== "undefined") {
41
- filled[pos] = parseInt(value, 10);
42
- }
43
- }
44
- return filled;
45
- }
46
-
47
- function makeDTF(zone) {
48
- return new Intl.DateTimeFormat("en-US", {
49
- hourCycle: "h23",
50
- timeZone: zone,
51
- year: "numeric",
52
- month: "2-digit",
53
- day: "2-digit",
54
- hour: "2-digit",
55
- minute: "2-digit",
56
- second: "2-digit",
57
- });
58
- }
59
-
60
- // covert a calendar object to a local timestamp (epoch, but with the offset baked in)
61
- function objToLocalTS(obj) {
62
- let d = Date.UTC(
63
- obj.year,
64
- obj.month - 1,
65
- obj.day,
66
- obj.hour,
67
- obj.minute,
68
- obj.second,
69
- obj.millisecond,
70
- );
71
-
72
- // for legacy reasons, years between 0 and 99 are interpreted as 19XX; revert that
73
- if (obj.year < 100 && obj.year >= 0) {
74
- d = new Date(d);
75
- d.setUTCFullYear(d.getUTCFullYear() - 1900);
76
- }
77
- return +d;
78
- }
79
-
80
- export function getZoneOffset(timeZoneName) {
81
- if (!isValidIanaSpecifier(timeZoneName)) {
82
- return false;
83
- }
84
-
85
- const date = new Date(Date.now());
86
-
87
- let dtf;
88
-
89
- try {
90
- dtf = makeDTF(timeZoneName);
91
- } catch (_) {
92
- return false;
93
- }
94
-
95
- const [year, month, day, hour, minute, second] = dtf.formatToParts
96
- ? partsOffset(dtf, date)
97
- : hackyOffset(dtf, date);
98
-
99
- const asUTC = objToLocalTS({
100
- year,
101
- month,
102
- day,
103
- hour,
104
- minute,
105
- second,
106
- millisecond: 0,
107
- });
108
-
109
- let asTS = +date;
110
- const over = asTS % 1000;
111
- asTS -= over >= 0 ? over : 1000 + over;
112
- return (asUTC - asTS) / (60 * 1000);
113
- }