From 454c978be0586bdca9dd9ff4bcda462c52abb35a Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Fri, 23 Aug 2019 07:25:59 +0200 Subject: [PATCH] parseDateTime() fix coding error --- CHANGELOG.md | 1 + docs/history.html | 5 +++++ docs/index.html | 2 +- lib/util.js | 15 ++++++++++----- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d918cc7..658139a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ For major (breaking) changes - version 3 and 2 see end of page. | Version | Date | Comment | | -------------- | -------------- | -------- | +| 4.14.8 | 2019-08-22 | `parseDateTime()` fix coding error | | 4.14.7 | 2019-08-22 | `battery()` windows acconnected improvement | | 4.14.6 | 2019-08-22 | `users()` improved date time parsing | | 4.14.5 | 2019-08-22 | `fsSize()` fix windows result as number | diff --git a/docs/history.html b/docs/history.html index d89def3..3e8df78 100644 --- a/docs/history.html +++ b/docs/history.html @@ -83,6 +83,11 @@ + + 4.14.8 + 2019-08-23 + parseDateTime() fix coding error + 4.14.7 2019-08-22 diff --git a/docs/index.html b/docs/index.html index 3eaa96e..a6f3182 100644 --- a/docs/index.html +++ b/docs/index.html @@ -168,7 +168,7 @@
systeminformation
-
Current Version: 4.14.7
+
Current Version: 4.14.8
diff --git a/lib/util.js b/lib/util.js index f9d1dab..7f39f58 100644 --- a/lib/util.js +++ b/lib/util.js @@ -132,7 +132,7 @@ function parseTime(t) { hour = isPM && hour < 12 ? hour + 12 : hour; return ('0' + hour).substr(-2) + ':' + ('0' + min).substr(-2); } - let parts = t.split('.'); + parts = t.split('.'); if (parts.length >= 2) { let isPM = (parts[1] && (parts[1].toLowerCase().indexOf('pm') > -1) || (parts[1].toLowerCase().indexOf('p.m.') > -1) || (parts[1].toLowerCase().indexOf('p. m.') > -1) || (parts[1].toLowerCase().indexOf('n') > -1) || (parts[1].toLowerCase().indexOf('ch') > -1) || (parts[1].toLowerCase().indexOf('ös') > -1)); hour = parseInt(parts[0], 10); @@ -140,7 +140,7 @@ function parseTime(t) { hour = isPM && hour < 12 ? hour + 12 : hour; return ('0' + hour).substr(-2) + ':' + ('0' + min).substr(-2); } - let parts = t.split(' '); + parts = t.split(' '); if (parts.length >= 2) { let isPM = ((t.toLowerCase().indexOf('pm') > -1) || (t.toLowerCase().indexOf('p.m.') > -1) || (t.toLowerCase().indexOf('p. m.') > -1) || (t.toLowerCase().indexOf('n') > -1) || (t.toLowerCase().indexOf('ch') > -1) || (t.toLowerCase().indexOf('ös') > -1)); hour = parseInt(parts[0], 10); @@ -173,8 +173,14 @@ function parseDateTime(dt) { result.date = '20' + dtparts[2] + '-' + ('0' + dtparts[1]).substr(-2) + '-' + ('0' + dtparts[0]).substr(-2); } else { // Dateformat: mm/dd/yyyy or dd/mm/yyyy - result.date = dtparts[2] + '-' + ('0' + dtparts[0]).substr(-2) + '-' + ('0' + dtparts[1]).substr(-2); - + const isEN = ((dt.toLowerCase().indexOf('pm') > -1) || (dt.toLowerCase().indexOf('p.m.') > -1) || (dt.toLowerCase().indexOf('p. m.') > -1) || (dt.toLowerCase().indexOf('am') > -1) || (dt.toLowerCase().indexOf('a.m.') > -1) || (dt.toLowerCase().indexOf('a. m.') > -1)); + if (isEN) { + // Dateformat: mm/dd/yyyy + result.date = dtparts[2] + '-' + ('0' + dtparts[0]).substr(-2) + '-' + ('0' + dtparts[1]).substr(-2); + } else { + // Dateformat: dd/mm/yyyy + result.date = dtparts[2] + '-' + ('0' + dtparts[1]).substr(-2) + '-' + ('0' + dtparts[0]).substr(-2); + } } } } @@ -187,7 +193,6 @@ function parseDateTime(dt) { } if (parts[0].indexOf('-') >= 0) { // Dateformat: yyyy-mm-dd - const isEN = ((dt.toLowerCase().indexOf('pm') > -1) || (t.toLowerCase().indexOf('p.m.') > -1) || (t.toLowerCase().indexOf('p. m.') > -1) || (dt.toLowerCase().indexOf('am') > -1) || (t.toLowerCase().indexOf('a.m.') > -1) || (t.toLowerCase().indexOf('a. m.') > -1)); const dtparts = parts[0].split('-'); if (dtparts.length === 3) { result.date = dtparts[0] + '-' + ('0' + dtparts[1]).substr(-2) + '-' + ('0' + dtparts[2]).substr(-2);