1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = getTimeZones;
|
7 |
|
8 | var _rawTimeZones = _interopRequireDefault(require("../raw-time-zones.json"));
|
9 |
|
10 | var _formatTimeZone = _interopRequireDefault(require("./formatTimeZone.js"));
|
11 |
|
12 | var _timeZone = require("./utils/timeZone.js");
|
13 |
|
14 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15 |
|
16 | function getTimeZones(opts) {
|
17 | const includeUtc = !!opts && opts.includeUtc;
|
18 | return _rawTimeZones.default.reduce(function (acc, timeZone) {
|
19 | const timeZoneName = timeZone.name;
|
20 | const currentOffset = (0, _timeZone.getZoneOffset)(timeZoneName);
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | if (currentOffset === false) {
|
26 | return acc;
|
27 | }
|
28 |
|
29 | const timeZoneWithCurrentTimeData = { ...timeZone,
|
30 | currentTimeOffsetInMinutes: currentOffset
|
31 | };
|
32 | acc.push({ ...timeZoneWithCurrentTimeData,
|
33 | currentTimeFormat: (0, _formatTimeZone.default)(timeZoneWithCurrentTimeData, {
|
34 | useCurrentOffset: true
|
35 | })
|
36 | });
|
37 | return acc;
|
38 | }, includeUtc ? [utcTimezone] : []).sort((a, b) => {
|
39 | return compareNumbers(a, b) || compareStrings(a.alternativeName, b.alternativeName) || compareStrings(a.mainCities[0], b.mainCities[0]);
|
40 | });
|
41 | }
|
42 |
|
43 | function compareNumbers(x, y) {
|
44 | return x.currentTimeOffsetInMinutes - y.currentTimeOffsetInMinutes;
|
45 | }
|
46 |
|
47 | function compareStrings(x, y) {
|
48 | if (typeof x === "string" && typeof y === "string") {
|
49 | return x.localeCompare(y);
|
50 | }
|
51 |
|
52 | return 0;
|
53 | }
|
54 |
|
55 | const utcTimezone = {
|
56 | name: "Etc/UTC",
|
57 | alternativeName: "Coordinated Universal Time (UTC)",
|
58 | abbreviation: "UTC",
|
59 | group: ["Etc/UTC", "Etc/UCT", "UCT", "UTC", "Universal", "Zulu"],
|
60 | countryName: "",
|
61 | continentCode: "",
|
62 | continentName: "",
|
63 | mainCities: [""],
|
64 | rawOffsetInMinutes: 0,
|
65 | rawFormat: "+00:00 Coordinated Universal Time (UTC)",
|
66 | currentTimeOffsetInMinutes: 0,
|
67 | currentTimeFormat: "+00:00 Coordinated Universal Time (UTC)"
|
68 | };
|
69 |
|
\ | No newline at end of file |