diff --git a/CHANGELOG.md b/CHANGELOG.md index f9d70c2..17d30d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -90,6 +90,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page. | Version | Date | Comment | | ------- | ---------- | --------------------------------------------------------------------------------------------------- | +| 5.24.5 | 2025-01-02 | `users()` improved date parsing (macOS) | | 5.24.4 | 2025-01-02 | `__proto__` added prototypes | | 5.24.3 | 2025-01-01 | `__proto__` deno compatibility | | 5.24.2 | 2025-01-01 | `versions()` fixed node version | diff --git a/docs/history.html b/docs/history.html index ef44483..957cc76 100644 --- a/docs/history.html +++ b/docs/history.html @@ -57,6 +57,11 @@ + + 5.24.5 + 2025-01-02 + users() improved date parsing (macOS) + 5.24.4 2025-01-02 diff --git a/docs/index.html b/docs/index.html index 94fa8a8..1969bec 100644 --- a/docs/index.html +++ b/docs/index.html @@ -170,7 +170,7 @@
systeminformation
 
- 3
New Version: 5.24.4
+ 3
New Version: 5.24.5
diff --git a/lib/users.js b/lib/users.js index e6ffc3b..960f438 100644 --- a/lib/users.js +++ b/lib/users.js @@ -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');