parseDateTime() fix coding error

This commit is contained in:
Sebastian Hildebrandt 2019-08-23 07:25:59 +02:00
parent b38b555e47
commit 454c978be0
4 changed files with 17 additions and 6 deletions

View File

@ -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 |

View File

@ -83,6 +83,11 @@
</tr>
</thead>
<tbody>
<tr>
<th scope="row">4.14.8</th>
<td>2019-08-23</td>
<td><span class="code">parseDateTime()</span> fix coding error</td>
</tr>
<tr>
<th scope="row">4.14.7</th>
<td>2019-08-22</td>

View File

@ -168,7 +168,7 @@
<img class="logo" src="assets/logo.png">
<div class="title">systeminformation</div>
<div class="subtitle"><span id="typed"></span></div>
<div class="version">Current Version: <span id="version">4.14.7</span></div>
<div class="version">Current Version: <span id="version">4.14.8</span></div>
<button class="btn btn-light" onclick="location.href='https://github.com/sebhildebrandt/systeminformation'">View on Github <i class=" fab fa-github"></i></button>
</div>
<div class="down">

View File

@ -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);