-
Notifications
You must be signed in to change notification settings - Fork 0
/
timezone.js
40 lines (38 loc) · 1.19 KB
/
timezone.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
const {exec} = require('child_process');
const configHelper = require('./config');
const config = configHelper.getConfig();
module.exports = {
getTimezone() {
return config.timezone;
},
setTimezone(timezoneName, timezoneString) {
return new Promise((resolve, reject) => {
exec(`onion time set ${timezoneName} ${timezoneString}`, (error, stdout, stderr) => {
if (error) {
console.error(`Error Code: ${error.code}, Error Signal: ${error.signal}`);
reject(stderr.toString());
} else {
resolve(stdout.toString());
}
});
});
},
getTimezones() {
return new Promise((resolve, reject) => {
exec('onion time list', (error, stdout, stderr) => {
if (error) {
console.error(`Error Code: ${error.code}, Error Signal: ${error.signal}`);
reject(stderr.toString());
} else {
const parsedTimezones = stdout
.toString()
.split('\n')
.map(timezone => timezone.split('\t'));
parsedTimezones.shift(); // remove header
parsedTimezones.pop(); // remove empty last line
resolve(parsedTimezones);
}
});
});
}
}