systeminformation 4.23.1 → 4.23.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/README.md +1 -1
- package/lib/battery.js +5 -2
- package/lib/cpu.js +8 -9
- package/lib/filesystem.js +2 -2
- package/lib/memory.js +2 -1
- package/lib/network.js +25 -7
- package/lib/osinfo.js +4 -4
- package/lib/system.js +1 -1
- package/lib/users.js +46 -5
- package/lib/util.js +46 -30
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -30,6 +30,10 @@ For major (breaking) changes - version 3 and 2 see end of page.
|
|
|
30
30
|
|
|
31
31
|
| Version | Date | Comment |
|
|
32
32
|
| -------------- | -------------- | -------- |
|
|
33
|
+
| 4.23.5 | 2020-04-20 | updated docs |
|
|
34
|
+
| 4.23.4 | 2020-04-20 | `users()` optimized parseDateTime function |
|
|
35
|
+
| 4.23.3 | 2020-04-09 | recactored to avoid `cat` |
|
|
36
|
+
| 4.23.2 | 2020-04-08 | `cpu()` fixed getting base frequency for AMD Ryzen |
|
|
33
37
|
| 4.23.1 | 2020-03-11 | `diskLayout()` optimized detection linux |
|
|
34
38
|
| 4.23.0 | 2020-03-08 | `versions()` added param to specify which program/lib versions to detect |
|
|
35
39
|
| 4.22.7 | 2020-03-08 | `diskLayout()` fixed linux |
|
package/README.md
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
[![Sponsoring][sponsor-badge]][sponsor-url]
|
|
31
31
|
[![MIT license][license-img]][license-url]
|
|
32
32
|
|
|
33
|
-
This is amazing. Started as a small project just for myself, it now has > 9,000 lines of code, > 300 versions published,
|
|
33
|
+
This is amazing. Started as a small project just for myself, it now has > 9,000 lines of code, > 300 versions published, > 1 mio downloads per month, > 9 mio downloads overall. Thank you to all who contributed to this project!
|
|
34
34
|
|
|
35
35
|
## New Version 4.0
|
|
36
36
|
|
package/lib/battery.js
CHANGED
|
@@ -57,7 +57,7 @@ module.exports = function (callback) {
|
|
|
57
57
|
battery_path = '/sys/class/power_supply/BAT0/';
|
|
58
58
|
}
|
|
59
59
|
if (battery_path) {
|
|
60
|
-
|
|
60
|
+
fs.readFile(battery_path + 'uevent', function (error, stdout) {
|
|
61
61
|
if (!error) {
|
|
62
62
|
let lines = stdout.toString().split('\n');
|
|
63
63
|
|
|
@@ -67,7 +67,7 @@ module.exports = function (callback) {
|
|
|
67
67
|
result.capacityUnit = result.voltage ? 'mWh' : 'mAh';
|
|
68
68
|
result.cyclecount = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CYCLE_COUNT', '='), 10);
|
|
69
69
|
result.maxcapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL', '='), 10) / 1000.0 / (result.voltage || 1));
|
|
70
|
-
result.designedcapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL_DESIGN', '='), 10) / 1000.0 / (result.voltage || 1))| result.maxcapacity;
|
|
70
|
+
result.designedcapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL_DESIGN', '='), 10) / 1000.0 / (result.voltage || 1)) | result.maxcapacity;
|
|
71
71
|
result.currentcapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_NOW', '='), 10) / 1000.0 / (result.voltage || 1));
|
|
72
72
|
if (!result.maxcapacity) {
|
|
73
73
|
result.maxcapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_FULL', '='), 10) / 1000.0;
|
|
@@ -100,6 +100,9 @@ module.exports = function (callback) {
|
|
|
100
100
|
result.serial = util.getValue(lines, 'POWER_SUPPLY_SERIAL_NUMBER', '=');
|
|
101
101
|
if (callback) { callback(result); }
|
|
102
102
|
resolve(result);
|
|
103
|
+
} else {
|
|
104
|
+
if (callback) { callback(result); }
|
|
105
|
+
resolve(result);
|
|
103
106
|
}
|
|
104
107
|
});
|
|
105
108
|
} else {
|
package/lib/cpu.js
CHANGED
|
@@ -232,7 +232,7 @@ const AMDBaseFrequencies = {
|
|
|
232
232
|
'7351P': '2.4',
|
|
233
233
|
'2300X': '3.5',
|
|
234
234
|
'2500X': '3.6',
|
|
235
|
-
'2600': '3.
|
|
235
|
+
'2600': '3.4',
|
|
236
236
|
'2600E': '3.1',
|
|
237
237
|
'2600X': '3.6',
|
|
238
238
|
'2700': '3.2',
|
|
@@ -452,7 +452,7 @@ function getCpu() {
|
|
|
452
452
|
modelline = util.getValue(lines, 'model name') || modelline;
|
|
453
453
|
result.brand = modelline.split('@')[0].trim();
|
|
454
454
|
result.speed = modelline.split('@')[1] ? parseFloat(modelline.split('@')[1].trim()).toFixed(2) : '0.00';
|
|
455
|
-
if (result.speed === '0.00' && result.brand.indexOf('AMD') > -1) {
|
|
455
|
+
if (result.speed === '0.00' && (result.brand.indexOf('AMD') > -1 || result.brand.toLowerCase().indexOf('ryzen') > -1)) {
|
|
456
456
|
result.speed = getAMDSpeed(result.brand);
|
|
457
457
|
}
|
|
458
458
|
if (result.speed === '0.00') {
|
|
@@ -517,7 +517,7 @@ function getCpu() {
|
|
|
517
517
|
}
|
|
518
518
|
result.brand = modelline.split('@')[0].trim();
|
|
519
519
|
result.speed = modelline.split('@')[1] ? parseFloat(modelline.split('@')[1].trim()).toFixed(2) : '0.00';
|
|
520
|
-
if (result.speed === '0.00' && result.brand.indexOf('AMD') > -1) {
|
|
520
|
+
if (result.speed === '0.00' && (result.brand.indexOf('AMD') > -1 || result.brand.toLowerCase().indexOf('ryzen') > -1)) {
|
|
521
521
|
result.speed = getAMDSpeed(result.brand);
|
|
522
522
|
}
|
|
523
523
|
if (result.speed === '0.00') {
|
|
@@ -582,12 +582,11 @@ function getCpu() {
|
|
|
582
582
|
let name = util.getValue(lines, 'name', '=') || '';
|
|
583
583
|
if (name.indexOf('@') >= 0) {
|
|
584
584
|
result.brand = name.split('@')[0].trim();
|
|
585
|
-
result.speed = name.split('@')[1].trim();
|
|
586
|
-
result.speed = parseFloat(result.speed.replace(/GHz+/g, '').trim()).toFixed(2);
|
|
585
|
+
result.speed = name.split('@')[1] ? parseFloat(name.split('@')[1].trim()).toFixed(2) : '0.00';
|
|
587
586
|
_cpu_speed = result.speed;
|
|
588
587
|
} else {
|
|
589
588
|
result.brand = name.trim();
|
|
590
|
-
result.speed = 0;
|
|
589
|
+
result.speed = '0.00';
|
|
591
590
|
}
|
|
592
591
|
result = cpuBrandManufacturer(result);
|
|
593
592
|
result.revision = util.getValue(lines, 'revision', '=');
|
|
@@ -600,7 +599,7 @@ function getCpu() {
|
|
|
600
599
|
result.vendor = util.getValue(lines, 'manufacturer', '=');
|
|
601
600
|
result.speedmax = Math.round(parseFloat(util.getValue(lines, 'maxclockspeed', '=').replace(/,/g, '.')) / 10.0) / 100;
|
|
602
601
|
result.speedmax = result.speedmax ? parseFloat(result.speedmax).toFixed(2) : '';
|
|
603
|
-
if (
|
|
602
|
+
if (result.speed === '0.00' && (result.brand.indexOf('AMD') > -1 || result.brand.toLowerCase().indexOf('ryzen') > -1)) {
|
|
604
603
|
result.speed = getAMDSpeed(result.brand);
|
|
605
604
|
}
|
|
606
605
|
if (result.speed === '0.00') {
|
|
@@ -781,7 +780,7 @@ function cpuTemperature(callback) {
|
|
|
781
780
|
} else {
|
|
782
781
|
fs.stat('/sys/class/thermal/thermal_zone0/temp', function (err) {
|
|
783
782
|
if (err === null) {
|
|
784
|
-
|
|
783
|
+
fs.readFile('/sys/class/thermal/thermal_zone0/temp', function (error, stdout) {
|
|
785
784
|
if (!error) {
|
|
786
785
|
let lines = stdout.toString().split('\n');
|
|
787
786
|
if (lines.length > 0) {
|
|
@@ -929,7 +928,7 @@ function cpuFlags(callback) {
|
|
|
929
928
|
});
|
|
930
929
|
}
|
|
931
930
|
if (!result) {
|
|
932
|
-
|
|
931
|
+
fs.readFile('/proc/cpuinfo', function (error, stdout) {
|
|
933
932
|
if (!error) {
|
|
934
933
|
let lines = stdout.toString().split('\n');
|
|
935
934
|
result = util.getValue(lines, 'features', ':', true).toLowerCase();
|
package/lib/filesystem.js
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
const exec = require('child_process').exec;
|
|
17
17
|
const execSync = require('child_process').execSync;
|
|
18
18
|
const util = require('./util');
|
|
19
|
+
const fs = require('fs');
|
|
19
20
|
|
|
20
21
|
let _platform = process.platform;
|
|
21
22
|
|
|
@@ -159,8 +160,7 @@ function fsOpenFiles(callback) {
|
|
|
159
160
|
});
|
|
160
161
|
}
|
|
161
162
|
if (_linux) {
|
|
162
|
-
|
|
163
|
-
exec(cmd, function (error, stdout) {
|
|
163
|
+
fs.readFile('/proc/sys/fs/file-nr', function (error, stdout) {
|
|
164
164
|
if (!error) {
|
|
165
165
|
let lines = stdout.toString().split('\n');
|
|
166
166
|
if (lines[0]) {
|
package/lib/memory.js
CHANGED
|
@@ -17,6 +17,7 @@ const os = require('os');
|
|
|
17
17
|
const exec = require('child_process').exec;
|
|
18
18
|
const execSync = require('child_process').execSync;
|
|
19
19
|
const util = require('./util');
|
|
20
|
+
const fs = require('fs');
|
|
20
21
|
|
|
21
22
|
let _platform = process.platform;
|
|
22
23
|
|
|
@@ -143,7 +144,7 @@ function mem(callback) {
|
|
|
143
144
|
};
|
|
144
145
|
|
|
145
146
|
if (_linux) {
|
|
146
|
-
|
|
147
|
+
fs.readFile('/proc/meminfo', function (error, stdout) {
|
|
147
148
|
if (!error) {
|
|
148
149
|
const lines = stdout.toString().split('\n');
|
|
149
150
|
result.total = parseInt(util.getValue(lines, 'memtotal'), 10);
|
package/lib/network.js
CHANGED
|
@@ -198,7 +198,7 @@ function parseLinesWindowsNics(sections, nconfigsections) {
|
|
|
198
198
|
let linesNicConfig = nconfigsections[i].trim().split('\r\n');
|
|
199
199
|
let netEnabled = util.getValue(lines, 'NetEnabled', '=');
|
|
200
200
|
|
|
201
|
-
if (netEnabled) {
|
|
201
|
+
if (netEnabled !== '') {
|
|
202
202
|
const speed = parseInt(util.getValue(lines, 'speed', '=').trim(), 10) / 1000000;
|
|
203
203
|
nics.push({
|
|
204
204
|
mac: util.getValue(lines, 'MACAddress', '=').toLowerCase(),
|
|
@@ -560,13 +560,13 @@ function getLinuxIfaceDHCPstatus(iface, connectionName, DHCPNics) {
|
|
|
560
560
|
|
|
561
561
|
let dhcStatus = resultFormat.split(' ').slice(1).toString();
|
|
562
562
|
switch (dhcStatus) {
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
563
|
+
case 'auto':
|
|
564
|
+
result = true;
|
|
565
|
+
break;
|
|
566
566
|
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
567
|
+
default:
|
|
568
|
+
result = false;
|
|
569
|
+
break;
|
|
570
570
|
}
|
|
571
571
|
return result;
|
|
572
572
|
} catch (e) {
|
|
@@ -656,6 +656,24 @@ function networkInterfaces(callback) {
|
|
|
656
656
|
return new Promise((resolve) => {
|
|
657
657
|
process.nextTick(() => {
|
|
658
658
|
let ifaces = os.networkInterfaces();
|
|
659
|
+
if (_windows) {
|
|
660
|
+
getWindowsNics().forEach(nic => {
|
|
661
|
+
let found = false;
|
|
662
|
+
Object.keys(ifaces).forEach(key => {
|
|
663
|
+
if (!found) {
|
|
664
|
+
ifaces[key].forEach(value => {
|
|
665
|
+
if (Object.keys(value).indexOf('mac') >= 0) {
|
|
666
|
+
found = value['mac'] === nic.mac;
|
|
667
|
+
}
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
if (!found) {
|
|
673
|
+
ifaces[nic.name] = [{ mac: nic.mac }];
|
|
674
|
+
}
|
|
675
|
+
});
|
|
676
|
+
}
|
|
659
677
|
let result = [];
|
|
660
678
|
let nics = [];
|
|
661
679
|
let dnsSuffixes = [];
|
package/lib/osinfo.js
CHANGED
|
@@ -391,7 +391,7 @@ function versions(apps, callback) {
|
|
|
391
391
|
return {
|
|
392
392
|
versions: versionObject,
|
|
393
393
|
counter: 26
|
|
394
|
-
}
|
|
394
|
+
};
|
|
395
395
|
}
|
|
396
396
|
if (!Array.isArray(apps)) {
|
|
397
397
|
apps = apps.trim().toLowerCase().replace(/,+/g, '|').replace(/ /g, '|');
|
|
@@ -399,7 +399,7 @@ function versions(apps, callback) {
|
|
|
399
399
|
const result = {
|
|
400
400
|
versions: {},
|
|
401
401
|
counter: 0
|
|
402
|
-
}
|
|
402
|
+
};
|
|
403
403
|
apps.forEach(el => {
|
|
404
404
|
if (el) {
|
|
405
405
|
for (let key in versionObject) {
|
|
@@ -807,8 +807,8 @@ function versions(apps, callback) {
|
|
|
807
807
|
});
|
|
808
808
|
}
|
|
809
809
|
} catch (e) {
|
|
810
|
-
if (callback) { callback(
|
|
811
|
-
resolve(
|
|
810
|
+
if (callback) { callback(appsObj.versions); }
|
|
811
|
+
resolve(appsObj.versions);
|
|
812
812
|
}
|
|
813
813
|
});
|
|
814
814
|
});
|
package/lib/system.js
CHANGED
|
@@ -88,7 +88,7 @@ function system(callback) {
|
|
|
88
88
|
|
|
89
89
|
if (result.manufacturer === '' && result.model === 'Computer' && result.version === '') {
|
|
90
90
|
// Check Raspberry Pi
|
|
91
|
-
|
|
91
|
+
fs.readFile('/proc/cpuinfo', function (error, stdout) {
|
|
92
92
|
if (!error) {
|
|
93
93
|
let lines = stdout.toString().split('\n');
|
|
94
94
|
result.model = util.getValue(lines, 'hardware', ':', true).toUpperCase();
|
package/lib/users.js
CHANGED
|
@@ -26,9 +26,44 @@ const _openbsd = (_platform === 'openbsd');
|
|
|
26
26
|
const _netbsd = (_platform === 'netbsd');
|
|
27
27
|
const _sunos = (_platform === 'sunos');
|
|
28
28
|
|
|
29
|
+
let _winDateFormat = {
|
|
30
|
+
dateFormat: '',
|
|
31
|
+
dateSeperator: '',
|
|
32
|
+
timeFormat: '',
|
|
33
|
+
timeSeperator: '',
|
|
34
|
+
amDesignator: '',
|
|
35
|
+
pmDesignator: ''
|
|
36
|
+
};
|
|
37
|
+
|
|
29
38
|
// --------------------------
|
|
30
39
|
// array of users online = sessions
|
|
31
40
|
|
|
41
|
+
function getWinCulture() {
|
|
42
|
+
return new Promise((resolve) => {
|
|
43
|
+
process.nextTick(() => {
|
|
44
|
+
if (!_winDateFormat.dateFormat) {
|
|
45
|
+
util.powerShell('(get-culture).DateTimeFormat')
|
|
46
|
+
.then(data => {
|
|
47
|
+
let lines = data.toString().split('\r\n');
|
|
48
|
+
_winDateFormat.dateFormat = util.getValue(lines, 'ShortDatePattern', ':');
|
|
49
|
+
_winDateFormat.dateSeperator = util.getValue(lines, 'DateSeparator', ':');
|
|
50
|
+
_winDateFormat.timeFormat = util.getValue(lines, 'ShortTimePattern', ':');
|
|
51
|
+
_winDateFormat.timeSeperator = util.getValue(lines, 'TimeSeparator', ':');
|
|
52
|
+
_winDateFormat.amDesignator = util.getValue(lines, 'AMDesignator', ':');
|
|
53
|
+
_winDateFormat.pmDesignator = util.getValue(lines, 'PMDesignator', ':');
|
|
54
|
+
|
|
55
|
+
resolve(_winDateFormat);
|
|
56
|
+
})
|
|
57
|
+
.catch(() => {
|
|
58
|
+
resolve(_winDateFormat);
|
|
59
|
+
});
|
|
60
|
+
} else {
|
|
61
|
+
resolve(_winDateFormat);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
32
67
|
function parseUsersLinux(lines, phase) {
|
|
33
68
|
let result = [];
|
|
34
69
|
let result_who = [];
|
|
@@ -141,7 +176,7 @@ function parseUsersDarwin(lines) {
|
|
|
141
176
|
return result;
|
|
142
177
|
}
|
|
143
178
|
|
|
144
|
-
function parseUsersWin(lines) {
|
|
179
|
+
function parseUsersWin(lines, culture) {
|
|
145
180
|
|
|
146
181
|
let result = [];
|
|
147
182
|
const header = lines[0];
|
|
@@ -164,7 +199,7 @@ function parseUsersWin(lines) {
|
|
|
164
199
|
if (lines[i].trim()) {
|
|
165
200
|
const user = lines[i].substring(headerDelimiter[0] + 1, headerDelimiter[1]).trim() || '';
|
|
166
201
|
const tty = lines[i].substring(headerDelimiter[1] + 1, headerDelimiter[2] - 2).trim() || '';
|
|
167
|
-
const dateTime = util.parseDateTime(lines[i].substring(headerDelimiter[5] + 1, 2000).trim()) || '';
|
|
202
|
+
const dateTime = util.parseDateTime(lines[i].substring(headerDelimiter[5] + 1, 2000).trim(), culture) || '';
|
|
168
203
|
result.push({
|
|
169
204
|
user: user,
|
|
170
205
|
tty: tty,
|
|
@@ -252,10 +287,16 @@ function users(callback) {
|
|
|
252
287
|
if (stdout) {
|
|
253
288
|
// lines / split
|
|
254
289
|
let lines = stdout.toString().split('\r\n');
|
|
255
|
-
|
|
290
|
+
getWinCulture()
|
|
291
|
+
.then(culture => {
|
|
292
|
+
result = parseUsersWin(lines, culture);
|
|
293
|
+
if (callback) { callback(result); }
|
|
294
|
+
resolve(result);
|
|
295
|
+
});
|
|
296
|
+
} else {
|
|
297
|
+
if (callback) { callback(result); }
|
|
298
|
+
resolve(result);
|
|
256
299
|
}
|
|
257
|
-
if (callback) { callback(result); }
|
|
258
|
-
resolve(result);
|
|
259
300
|
});
|
|
260
301
|
} catch (e) {
|
|
261
302
|
if (callback) { callback(result); }
|
package/lib/util.js
CHANGED
|
@@ -119,45 +119,51 @@ function decodeEscapeSequence(str, base) {
|
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
function
|
|
122
|
+
function detectSplit(str) {
|
|
123
|
+
let seperator = '';
|
|
124
|
+
let part = 0;
|
|
125
|
+
str.split('').forEach(element => {
|
|
126
|
+
if (element >= '0' && element <= '9') {
|
|
127
|
+
if (part === 1) { part++; }
|
|
128
|
+
} else {
|
|
129
|
+
if (part === 0) { part++; }
|
|
130
|
+
if (part === 1) {
|
|
131
|
+
seperator += element;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
return seperator;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function parseTime(t, pmDesignator) {
|
|
139
|
+
pmDesignator = pmDesignator || '';
|
|
123
140
|
t = t.toUpperCase();
|
|
124
141
|
let hour = 0;
|
|
125
142
|
let min = 0;
|
|
126
|
-
let
|
|
143
|
+
let splitter = detectSplit(t);
|
|
144
|
+
let parts = t.split(splitter);
|
|
127
145
|
if (parts.length >= 2) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return ('0' + hour).substr(-2) + ':' + ('0' + min).substr(-2);
|
|
133
|
-
}
|
|
134
|
-
parts = t.split('.');
|
|
135
|
-
if (parts.length >= 2) {
|
|
136
|
-
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));
|
|
146
|
+
if (parts[2]) {
|
|
147
|
+
parts[1] += parts[2];
|
|
148
|
+
}
|
|
149
|
+
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) || (pmDesignator && parts[1].toLowerCase().indexOf(pmDesignator) > -1));
|
|
137
150
|
hour = parseInt(parts[0], 10);
|
|
138
151
|
min = parseInt(parts[1], 10);
|
|
139
152
|
hour = isPM && hour < 12 ? hour + 12 : hour;
|
|
140
153
|
return ('0' + hour).substr(-2) + ':' + ('0' + min).substr(-2);
|
|
141
154
|
}
|
|
142
|
-
parts = t.split(' ');
|
|
143
|
-
if (parts.length >= 2) {
|
|
144
|
-
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));
|
|
145
|
-
hour = parseInt(parts[0], 10);
|
|
146
|
-
if (parts[1] === 'h' && parts[2]) {
|
|
147
|
-
min = parseInt(parts[2], 10);
|
|
148
|
-
} else {
|
|
149
|
-
min = parseInt(parts[1], 10);
|
|
150
|
-
}
|
|
151
|
-
hour = isPM && hour < 12 ? hour + 12 : hour;
|
|
152
|
-
return ('0' + hour).substr(-2) + ':' + ('0' + min).substr(-2);
|
|
153
|
-
}
|
|
154
155
|
}
|
|
155
156
|
|
|
156
|
-
function parseDateTime(dt) {
|
|
157
|
+
function parseDateTime(dt, culture) {
|
|
157
158
|
const result = {
|
|
158
159
|
date: '',
|
|
159
160
|
time: ''
|
|
160
161
|
};
|
|
162
|
+
culture = culture || {};
|
|
163
|
+
let dateFormat = (culture.dateFormat || '').toLowerCase();
|
|
164
|
+
let timeFormat = (culture.timeFormat || '');
|
|
165
|
+
let pmDesignator = (culture.pmDesignator || '');
|
|
166
|
+
|
|
161
167
|
const parts = dt.split(' ');
|
|
162
168
|
if (parts[0]) {
|
|
163
169
|
if (parts[0].indexOf('/') >= 0) {
|
|
@@ -168,12 +174,17 @@ function parseDateTime(dt) {
|
|
|
168
174
|
// Dateformat: yyyy/mm/dd
|
|
169
175
|
result.date = dtparts[0] + '-' + ('0' + dtparts[1]).substr(-2) + '-' + ('0' + dtparts[2]).substr(-2);
|
|
170
176
|
} else if (dtparts[2].length === 2) {
|
|
171
|
-
|
|
172
|
-
|
|
177
|
+
if ((dateFormat.indexOf('/d/') > -1 || dateFormat.indexOf('/dd/') > -1)) {
|
|
178
|
+
// Dateformat: mm/dd/yy
|
|
179
|
+
result.date = '20' + dtparts[2] + '-' + ('0' + dtparts[1]).substr(-2) + '-' + ('0' + dtparts[0]).substr(-2);
|
|
180
|
+
} else {
|
|
181
|
+
// Dateformat: dd/mm/yy
|
|
182
|
+
result.date = '20' + dtparts[2] + '-' + ('0' + dtparts[1]).substr(-2) + '-' + ('0' + dtparts[0]).substr(-2);
|
|
183
|
+
}
|
|
173
184
|
} else {
|
|
174
185
|
// Dateformat: mm/dd/yyyy or dd/mm/yyyy
|
|
175
186
|
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));
|
|
176
|
-
if (isEN) {
|
|
187
|
+
if ((isEN || dateFormat.indexOf('/d/') > -1 || dateFormat.indexOf('/dd/') > -1) && dateFormat.indexOf('dd/') !== 0) {
|
|
177
188
|
// Dateformat: mm/dd/yyyy
|
|
178
189
|
result.date = dtparts[2] + '-' + ('0' + dtparts[0]).substr(-2) + '-' + ('0' + dtparts[1]).substr(-2);
|
|
179
190
|
} else {
|
|
@@ -184,10 +195,15 @@ function parseDateTime(dt) {
|
|
|
184
195
|
}
|
|
185
196
|
}
|
|
186
197
|
if (parts[0].indexOf('.') >= 0) {
|
|
187
|
-
// Dateformat: dd.mm.yyyy
|
|
188
198
|
const dtparts = parts[0].split('.');
|
|
189
199
|
if (dtparts.length === 3) {
|
|
190
|
-
|
|
200
|
+
if (dateFormat.indexOf('.d.') > -1 || dateFormat.indexOf('.dd.') > -1) {
|
|
201
|
+
// Dateformat: mm.dd.yyyy
|
|
202
|
+
result.date = dtparts[2] + '-' + ('0' + dtparts[0]).substr(-2) + '-' + ('0' + dtparts[1]).substr(-2);
|
|
203
|
+
} else {
|
|
204
|
+
// Dateformat: dd.mm.yyyy
|
|
205
|
+
result.date = dtparts[2] + '-' + ('0' + dtparts[1]).substr(-2) + '-' + ('0' + dtparts[0]).substr(-2);
|
|
206
|
+
}
|
|
191
207
|
}
|
|
192
208
|
}
|
|
193
209
|
if (parts[0].indexOf('-') >= 0) {
|
|
@@ -201,7 +217,7 @@ function parseDateTime(dt) {
|
|
|
201
217
|
if (parts[1]) {
|
|
202
218
|
parts.shift();
|
|
203
219
|
let time = parts.join(' ');
|
|
204
|
-
result.time = parseTime(time);
|
|
220
|
+
result.time = parseTime(time, pmDesignator);
|
|
205
221
|
}
|
|
206
222
|
return result;
|
|
207
223
|
}
|
package/package.json
CHANGED