time() changed retrieval of timezones (linux, macOS)
This commit is contained in:
+19
-5
@@ -34,11 +34,25 @@ const _sunos = (_platform === 'sunos');
|
||||
|
||||
function time() {
|
||||
let t = new Date().toString().split(' ');
|
||||
return {
|
||||
current: Date.now(),
|
||||
uptime: os.uptime(),
|
||||
timezone: (t.length >= 7) ? t[5] : '',
|
||||
timezoneName: Intl ? Intl.DateTimeFormat().resolvedOptions().timeZone : (t.length >= 7) ? t.slice(6).join(' ').replace(/\(/g, '').replace(/\)/g, '') : ''
|
||||
if (_darwin || _linux) {
|
||||
const stdout = execSync('date +%Z && date +%z && ls -l /etc/localtime 2>/dev/null', util.execOptsLinux);
|
||||
const lines = stdout.toString().split(os.EOL);
|
||||
if (lines.length > 3 && !lines[0]) {
|
||||
lines.shift();
|
||||
}
|
||||
return {
|
||||
current: Date.now(),
|
||||
uptime: os.uptime(),
|
||||
timezone: lines[0] && lines[1] ? lines[0] + lines[1] : '',
|
||||
timezoneName: lines[2] && lines[2].indexOf('/zoneinfo/') > 0 ? (lines[2].split('/zoneinfo/')[1] || '') : ''
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
current: Date.now(),
|
||||
uptime: os.uptime(),
|
||||
timezone: (t.length >= 7) ? t[5] : '',
|
||||
timezoneName: Intl ? Intl.DateTimeFormat().resolvedOptions().timeZone : (t.length >= 7) ? t.slice(6).join(' ').replace(/\(/g, '').replace(/\)/g, '') : ''
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user