From 5993adeb796651c5865632136d021aac91a3b935 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Thu, 12 Dec 2024 08:02:18 +0100 Subject: [PATCH] time() changed retrieval of timezones (linux, macOS) --- CHANGELOG.md | 1 + docs/history.html | 5 +++++ docs/index.html | 2 +- lib/osinfo.js | 24 +++++++++++++++++++----- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7331bc..c608706 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.23.10 | 2024-12-12 | `time()` changed retrieval of timezones (linux, macOS) | | 5.23.9 | 2024-12-11 | `typings` added definitions with overload | | 5.23.8 | 2024-12-10 | `system()` added Raspberry 500 detection | | 5.23.7 | 2024-12-09 | `networkInterfaces()` sanitizing SSID names (windows) | diff --git a/docs/history.html b/docs/history.html index fcd2ea1..c6c96d9 100644 --- a/docs/history.html +++ b/docs/history.html @@ -57,6 +57,11 @@ + + 5.23.10 + 2024-12-12 + time() changes retrieval of timezones (linux, macOS) + 5.23.9 2024-12-11 diff --git a/docs/index.html b/docs/index.html index 798a69b..11fe7c1 100644 --- a/docs/index.html +++ b/docs/index.html @@ -170,7 +170,7 @@
systeminformation
 
-
New Version: 5.23.9
+
New Version: 5.23.10
diff --git a/lib/osinfo.js b/lib/osinfo.js index 33aa0c1..16eb807 100644 --- a/lib/osinfo.js +++ b/lib/osinfo.js @@ -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, '') : '' + }; }; }