fix(basic.gblib): NOW keyword is now formatting values with two zeros.

This commit is contained in:
Rodrigo Rodriguez 2021-08-16 17:38:05 -03:00
parent 5fceb974c1
commit 1ed7cfaf74
5 changed files with 106 additions and 51 deletions

7
package-lock.json generated
View file

@ -1,6 +1,6 @@
{
"name": "botserver",
"version": "2.0.129",
"version": "2.0.135",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -12883,6 +12883,11 @@
"moment": ">= 2.9.0"
}
},
"momentjs": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/momentjs/-/momentjs-2.0.0.tgz",
"integrity": "sha1-c9+QS0+kGPbjxgXoMc727VUY69Q="
},
"months": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/months/-/months-1.2.0.tgz",

View file

@ -87,6 +87,7 @@
"ibm-watson": "6.1.1",
"js-beautify": "1.13.13",
"marked": "2.0.7",
"momentjs": "^2.0.0",
"ms-rest-azure": "3.0.0",
"nexmo": "2.9.1",
"node-cron": "3.0.0",

View file

@ -143,9 +143,6 @@ export class DialogKeywords {
*
*/
public getWeekFromDate(date) {
if (!(date instanceof Date)) {
date = new Date(date);
}
const contentLocale = this.min.core.getParam<string>(
this.min.instance,
@ -153,7 +150,16 @@ export class DialogKeywords {
GBConfigService.get('DEFAULT_CONTENT_LANGUAGE')
);
return date.toLocaleString(this.getContentLocaleWithCulture(contentLocale), { weekday: 'short' });
let dt = SystemKeywords.getDateFromLocaleString(date, contentLocale);
if (dt) {
if (!(dt instanceof Date)) {
dt = new Date(dt);
}
let week = dt.toLocaleString(this.getContentLocaleWithCulture(contentLocale), { weekday: 'short' });
return week.substr(0,3);
}
return 'NULL';
}
/**
@ -241,16 +247,28 @@ export class DialogKeywords {
*
*/
public getHourFromDate(date) {
if (!(date instanceof Date)) {
date = new Date(date);
}
function addZero(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
return addZero(date.getHours()) + ':' + addZero(date.getMinutes());
const contentLocale = this.min.core.getParam<string>(
this.min.instance,
'Default Content Language',
GBConfigService.get('DEFAULT_CONTENT_LANGUAGE')
);
let dt = SystemKeywords.getDateFromLocaleString(date, contentLocale);
if (dt) {
if (!(dt instanceof Date)) {
dt = new Date(dt);
}
return addZero(dt.getHours()) + ':' + addZero(dt.getMinutes());
}
return 'NULL';
}
/**

View file

@ -103,7 +103,7 @@ export class GBVMService extends GBService {
}
else {
await s.deleteScheduleIfAny(min, mainName);
}
}
text = text.replace(/SET SCHEDULE (.*)/gi, '');
fs.writeFileSync(urlJoin(folder, vbsFile), text);
}
@ -246,12 +246,12 @@ export class GBVMService extends GBService {
code = code.replace(/(\w+)\s*=\s*find\s*(.*)\s*or talk\s*(.*)/gi, ($0, $1, $2, $3) => {
return `${$1} = sys().find(${$2})\n
if (!${$1}) {=
if (!${$1}) {
if (resolve){
resolve();
}
talk (${$3})\n;
return;
return -1;
}
`;
});
@ -792,7 +792,7 @@ export class GBVMService extends GBService {
// Creates a class DialogKeywords which is the *this* pointer
// in BASIC.
const user =step? await min.userProfile.get(step.context, {}): null;
const user = step ? await min.userProfile.get(step.context, {}) : null;
const sandbox: DialogKeywords = new DialogKeywords(min, deployer, step, user);
// Injects the .gbdialog generated code into the VM.
@ -821,7 +821,9 @@ export class GBVMService extends GBService {
let ret = null;
try {
ret = await sandbox[mainMethod](step);
if (ret == -1) {
await step.endDialog();
}
} catch (error) {
throw new Error(`BASIC ERROR: ${error.message ? error.message : error}\n Stack:${error.stack}`);
}

View file

@ -81,8 +81,18 @@ export class SystemKeywords {
}
public async sortBy(array, memberName) {
return array ? array.sort(p => { if (p) { return p[memberName]; } }) :
null;
return array;
// return array ? array.sort(p => {
// var c = new Date(a.date);
// var d = new Date(b.date);
// return c - d;
// });
// if (p) {
// return ;
// }
// }): null;
}
/**
@ -276,6 +286,35 @@ export class SystemKeywords {
return val;
}
public isValidDate(dt) {
const contentLocale = this.min.core.getParam<string>(
this.min.instance,
'Default Content Language',
GBConfigService.get('DEFAULT_CONTENT_LANGUAGE')
);
let date = SystemKeywords.getDateFromLocaleString(dt, contentLocale);
if (!date) {
return false;
}
if (!(date instanceof Date)) {
date = new Date(date);
}
return !isNaN(date.valueOf());
}
public isValidNumber(number) {
if (number === '') { return false }
return !isNaN(number);
}
public isValidHour(value) {
return /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/.test(value);
}
/**
* Finds a value or multi-value results in a tabular file.
*
@ -349,28 +388,6 @@ export class SystemKeywords {
GBConfigService.get('DEFAULT_CONTENT_LANGUAGE')
);
function isValidDate(dt) {
let date = SystemKeywords.getDateFromLocaleString(dt, contentLocale);
if (!date) {
return false;
}
if (!(date instanceof Date)) {
date = new Date(date);
}
return !isNaN(date.valueOf());
}
function isValidNumber(number) {
if (number === '') { return false }
return !isNaN(number);
}
function isValidHour(value) {
return /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/.test(value);
}
// Increments columnIndex by looping until find a column match.
const filters = [];
@ -389,12 +406,12 @@ export class SystemKeywords {
}
filter.columnIndex = columnIndex;
if (isValidHour(filter.value)) {
if (this.isValidHour(filter.value)) {
filter.dataType = 'hourInterval';
} else if (isValidDate(filter.value)) {
} else if (this.isValidDate(filter.value)) {
filter.value = SystemKeywords.getDateFromLocaleString(filter.value, contentLocale);
filter.dataType = 'date';
} else if (isValidNumber(filter.value)) {
} else if (this.isValidNumber(filter.value)) {
filter.value = Number.parseInt(filter.value);
filter.dataType = 'number';
} else {
@ -451,6 +468,11 @@ export class SystemKeywords {
case 'hourInterval':
switch (filter.operator) {
case '=':
if (result && result.toLowerCase().trim() === filter.value.toLowerCase().trim()) {
filterAcceptCount++;
}
break;
case 'in':
const e = result.split(';');
const hr = Number.parseInt(filter.value.split(':')[0]);
@ -522,22 +544,29 @@ export class SystemKeywords {
}
}
private static getDateFromLocaleString(date: any, contentLocale: any) {
const parts = /^([0-3]?[0-9]).([0-3]?[0-9]).((?:[0-9]{2})?[0-9]{2})$/gi.exec(date);
public static getDateFromLocaleString(date: any, contentLocale: any) {
let parts = /^([0-3]?[0-9]).([0-3]?[0-9]).((?:[0-9]{2})?[0-9]{2})\s*(10|11|12|[1-9]):([0-5][0-9])/gi.exec(date);
if (parts && parts[5]) {
switch (contentLocale) {
case 'pt':
return new Date(Number.parseInt(parts[3]), Number.parseInt(parts[2]) - 1, Number.parseInt(parts[1]),
Number.parseInt(parts[4]), Number.parseInt(parts[5]), 0, 0);
case 'en':
return new Date(Number.parseInt(parts[3]), Number.parseInt(parts[1]) - 1, Number.parseInt(parts[2]),
Number.parseInt(parts[4]), Number.parseInt(parts[5]), 0, 0);
}
}
parts = /^([0-3]?[0-9]).([0-3]?[0-9]).((?:[0-9]{2})?[0-9]{2})$/gi.exec(date);
if (parts && parts[3]) {
switch (contentLocale) {
case 'pt':
date = new Date(Number.parseInt(parts[2]), Number.parseInt(parts[1]), Number.parseInt(parts[3]), 0, 0, 0, 0);
break;
return new Date(Number.parseInt(parts[2]), Number.parseInt(parts[1]) - 1, Number.parseInt(parts[3]), 0, 0, 0, 0);
case 'en':
date = new Date(Number.parseInt(parts[1]), Number.parseInt(parts[2]), Number.parseInt(parts[3]), 0, 0, 0, 0);
break;
return new Date(Number.parseInt(parts[1]), Number.parseInt(parts[2]) - 1, Number.parseInt(parts[3]), 0, 0, 0, 0);
}
return date;
}
else {
return null;
}
return null;
}
/**