This repository has been archived by the owner on Jan 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 193
/
node-preparse.js
76 lines (68 loc) · 1.96 KB
/
node-preparse.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
69
70
71
72
73
74
75
76
var files = [ 'africa'
, 'antarctica'
, 'asia'
, 'australasia'
, 'backward'
, 'etcetera'
, 'europe'
, 'factory'
, 'northamerica'
, 'pacificnew'
, 'southamerica'
, 'systemv'
];
(function () {
var fs = require('fs')
, timezoneJS = require('./date')
, EXCLUDED = new RegExp('README|Makefile|factory|(\\.+)', 'i');
function parse(args) {
// Upgrade passed script args to real Array
if (args.length < 3) {
console.log('Usage: node node-preparse.js zoneFileDirectory [exemplarCities] > outputfile.json');
console.log('Ex. >>> node node-preparse.js olson_files "Asia/Tokyo, America/New_York, Europe/London" > major_cities.json');
console.log('Ex. >>> node node-preparse.js olson_files > all_cities.json');
return;
}
var baseDir = args[2]
, cities = args[3]
, result = {}
, _tz = timezoneJS.timezone;
_tz.loadingScheme = _tz.loadingSchemes.MANUAL_LOAD;
_tz.zoneFiles = files;
for (var i = 0; i < _tz.zoneFiles.length; i++) {
var zoneFile = _tz.zoneFiles[i];
if (EXCLUDED.test(zoneFile)) continue;
var zoneData = fs.readFileSync(baseDir + '/' + zoneFile, 'utf8');
_tz.parseZones(zoneData);
}
if (cities) {
cities = cities.replace(/ /g, '').split(',');
var zones = {};
var rules = {};
for (var i = 0; i < cities.length; i++) {
var city = cities[i];
zones[city] = _tz.zones[city];
}
for (var n in zones) {
var zList = zones[n];
for (var i = 0; i < zList.length; i++) {
var ruleKey = zList[i][1];
rules[ruleKey] = _tz.rules[ruleKey];
}
}
result.zones = zones;
result.rules = rules;
}
else {
result.zones = _tz.zones;
result.rules = _tz.rules;
}
console.log(JSON.stringify(result, function(key, value) {
if (typeof(value) == "number") {
return value.toString()
}
return value
}));
}
module.exports = parse(process.argv);
}).call(this);