diff --git a/docs/index.html b/docs/index.html index 0f685aa..3314585 100644 --- a/docs/index.html +++ b/docs/index.html @@ -207,7 +207,7 @@
Downloads last month
-
266
+
267
Dependends
diff --git a/lib/users.js b/lib/users.js index ce2f35d..a1589a4 100644 --- a/lib/users.js +++ b/lib/users.js @@ -31,7 +31,8 @@ let _winDateFormat = { dateSeperator: '', timeFormat: '', timeSeperator: '', - amDesignator: '' + amDesignator: '', + pmDesignator: '' }; // -------------------------- @@ -40,7 +41,7 @@ let _winDateFormat = { function getWinCulture() { return new Promise((resolve) => { process.nextTick(() => { - if (!_winDateFormat) { + if (!_winDateFormat.dateFormat) { util.powerShell('(get-culture).DateTimeFormat') .then(data => { let lines = data.toString().split('\r\n'); @@ -49,6 +50,7 @@ function getWinCulture() { _winDateFormat.timeFormat = util.getValue(lines, 'ShortTimePattern', ':'); _winDateFormat.timeSeperator = util.getValue(lines, 'TimeSeparator', ':'); _winDateFormat.amDesignator = util.getValue(lines, 'AMDesignator', ':'); + _winDateFormat.pmDesignator = util.getValue(lines, 'PMDesignator', ':'); resolve(_winDateFormat); }) @@ -288,10 +290,13 @@ function users(callback) { getWinCulture() .then(culture => { result = parseUsersWin(lines, culture); + if (callback) { callback(result); } + resolve(result); }); + } else { + if (callback) { callback(result); } + resolve(result); } - if (callback) { callback(result); } - resolve(result); }); } catch (e) { if (callback) { callback(result); } diff --git a/lib/util.js b/lib/util.js index eabe497..57524e3 100644 --- a/lib/util.js +++ b/lib/util.js @@ -135,9 +135,8 @@ function detectSplit(str) { return seperator; } -function parseTime(t, timeFormat, timeSeperator) { - timeFormat = timeFormat || ''; - timeSeperator = timeSeperator || ''; +function parseTime(t, pmDesignator) { + pmDesignator = pmDesignator || ''; t = t.toUpperCase(); let hour = 0; let min = 0; @@ -147,7 +146,7 @@ function parseTime(t, timeFormat, timeSeperator) { if (parts[2]) { parts[1] += parts[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) || timeSeperator); + 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)); hour = parseInt(parts[0], 10); min = parseInt(parts[1], 10); hour = isPM && hour < 12 ? hour + 12 : hour; @@ -163,8 +162,7 @@ function parseDateTime(dt, culture) { culture = culture || {}; let dateFormat = (culture.dateFormat || '').toLowerCase(); let timeFormat = (culture.timeFormat || ''); - // let dateSeperator = (culture.dateSeperator || ''); - let timeSeperator = (culture.timeSeperator || ''); + let pmDesignator = (culture.pmDesignator || ''); const parts = dt.split(' '); if (parts[0]) { @@ -175,13 +173,18 @@ function parseDateTime(dt, culture) { if (dtparts[0].length === 4) { // Dateformat: yyyy/mm/dd result.date = dtparts[0] + '-' + ('0' + dtparts[1]).substr(-2) + '-' + ('0' + dtparts[2]).substr(-2); - } else if (dtparts[2].length === 2 || dateFormat.indexOf('/mm/') > -1) { - // Dateformat: dd/mm/yy - result.date = '20' + dtparts[2] + '-' + ('0' + dtparts[1]).substr(-2) + '-' + ('0' + dtparts[0]).substr(-2); + } else if (dtparts[2].length === 2) { + if ((dateFormat.indexOf('/d/') > -1 || dateFormat.indexOf('/dd/') > -1)) { + // Dateformat: mm/dd/yy + result.date = '20' + dtparts[2] + '-' + ('0' + dtparts[1]).substr(-2) + '-' + ('0' + dtparts[0]).substr(-2); + } else { + // Dateformat: dd/mm/yy + result.date = '20' + dtparts[2] + '-' + ('0' + dtparts[1]).substr(-2) + '-' + ('0' + dtparts[0]).substr(-2); + } } else { // Dateformat: mm/dd/yyyy or dd/mm/yyyy 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.indexOf('/d/') > -1 || dateFormat.indexOf('/dd/') > -1) { + if ((isEN || dateFormat.indexOf('/d/') > -1 || dateFormat.indexOf('/dd/') > -1) && dateFormat.indexOf('dd/') !== 0) { // Dateformat: mm/dd/yyyy result.date = dtparts[2] + '-' + ('0' + dtparts[0]).substr(-2) + '-' + ('0' + dtparts[1]).substr(-2); } else { @@ -198,7 +201,7 @@ function parseDateTime(dt, culture) { // Dateformat: mm.dd.yyyy result.date = dtparts[2] + '-' + ('0' + dtparts[0]).substr(-2) + '-' + ('0' + dtparts[1]).substr(-2); } else { - // Dateformat: dd.mm.yyyy + // Dateformat: dd.mm.yyyy result.date = dtparts[2] + '-' + ('0' + dtparts[1]).substr(-2) + '-' + ('0' + dtparts[0]).substr(-2); } } @@ -214,7 +217,7 @@ function parseDateTime(dt, culture) { if (parts[1]) { parts.shift(); let time = parts.join(' '); - result.time = parseTime(time, timeFormat, timeSeperator); + result.time = parseTime(time, pmDesignator); } return result; }