users() improved date parsing (macOS)
This commit is contained in:
+11
-3
@@ -105,10 +105,18 @@ function parseUsersDarwin(lines) {
|
||||
|
||||
// who part
|
||||
if (is_whopart) {
|
||||
let dt = ('' + new Date().getFullYear()) + '-' + ('0' + ('JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC'.indexOf(l[2].toUpperCase()) / 3 + 1)).slice(-2) + '-' + ('0' + l[3]).slice(-2);
|
||||
try {
|
||||
if (new Date(dt) > new Date) {
|
||||
dt = ('' + (new Date().getFullYear() - 1)) + '-' + ('0' + ('JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC'.indexOf(l[2].toUpperCase()) / 3 + 1)).slice(-2) + '-' + ('0' + l[3]).slice(-2);
|
||||
}
|
||||
} catch {
|
||||
util.noop();
|
||||
}
|
||||
result_who.push({
|
||||
user: l[0],
|
||||
tty: l[1],
|
||||
date: ('' + new Date().getFullYear()) + '-' + ('0' + ('JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC'.indexOf(l[2].toUpperCase()) / 3 + 1)).slice(-2) + '-' + ('0' + l[3]).slice(-2),
|
||||
date: dt,
|
||||
time: l[4],
|
||||
});
|
||||
} else {
|
||||
@@ -146,7 +154,7 @@ function users(callback) {
|
||||
|
||||
// linux
|
||||
if (_linux) {
|
||||
exec('who --ips; echo "---"; w | tail -n +2', function (error, stdout) {
|
||||
exec('export LC_ALL=C; who --ips; echo "---"; w; unset LC_ALL | tail -n +2', function (error, stdout) {
|
||||
if (!error) {
|
||||
// lines / split
|
||||
let lines = stdout.toString().split('\n');
|
||||
@@ -195,7 +203,7 @@ function users(callback) {
|
||||
}
|
||||
|
||||
if (_darwin) {
|
||||
exec('who; echo "---"; w -ih', function (error, stdout) {
|
||||
exec('export LC_ALL=C; who; echo "---"; w -ih; unset LC_ALL', function (error, stdout) {
|
||||
if (!error) {
|
||||
// lines / split
|
||||
let lines = stdout.toString().split('\n');
|
||||
|
||||
Reference in New Issue
Block a user