new(basic.gblib): FORMAT function, @othonlima.
This commit is contained in:
parent
c844613c98
commit
d23524b7b8
3 changed files with 78 additions and 21 deletions
|
@ -316,6 +316,46 @@ export class DialogKeywords {
|
|||
}
|
||||
}
|
||||
|
||||
// https://weblog.west-wind.com/posts/2008/Mar/18/A-simple-formatDate-function-for-JavaScript
|
||||
public async format(value, format) {
|
||||
|
||||
var date = value;
|
||||
if (!format)
|
||||
format = "MM/dd/yyyy";
|
||||
|
||||
var month = date.getMonth() + 1;
|
||||
var year = date.getFullYear();
|
||||
|
||||
format = format.replace("MM", month.toString().padL(2, "0"));
|
||||
|
||||
if (format.indexOf("yyyy") > -1)
|
||||
format = format.replace("yyyy", year.toString());
|
||||
else if (format.indexOf("yy") > -1)
|
||||
format = format.replace("yy", year.toString().substr(2, 2));
|
||||
|
||||
format = format.replace("dd", date.getDate().toString().padL(2, "0"));
|
||||
|
||||
var hours = date.getHours();
|
||||
if (format.indexOf("t") > -1) {
|
||||
if (hours > 11)
|
||||
format = format.replace("t", "pm")
|
||||
else
|
||||
format = format.replace("t", "am")
|
||||
}
|
||||
if (format.indexOf("HH") > -1)
|
||||
format = format.replace("HH", hours.toString().padL(2, "0"));
|
||||
if (format.indexOf("hh") > -1) {
|
||||
if (hours > 12) hours - 12;
|
||||
if (hours == 0) hours = 12;
|
||||
format = format.replace("hh", hours.toString().padL(2, "0"));
|
||||
}
|
||||
if (format.indexOf("mm") > -1)
|
||||
format = format.replace("mm", date.getMinutes().toString().padL(2, "0"));
|
||||
if (format.indexOf("ss") > -1)
|
||||
format = format.replace("ss", date.getSeconds().toString().padL(2, "0"));
|
||||
return format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns specified date week day in format 'Mon'.
|
||||
*
|
||||
|
@ -349,6 +389,8 @@ export class DialogKeywords {
|
|||
ret.setDate(ret.getDate() + 7 * units);
|
||||
break;
|
||||
case 'day':
|
||||
case 'days':
|
||||
case 'd':
|
||||
ret.setDate(ret.getDate() + units);
|
||||
break;
|
||||
case 'hour':
|
||||
|
|
|
@ -416,11 +416,18 @@ export class GBVMService extends GBService {
|
|||
|
||||
});
|
||||
|
||||
if (sync) {
|
||||
const shouldSync = min.core.getParam<boolean>(
|
||||
min.instance,
|
||||
'Synchronize Database',
|
||||
false
|
||||
);
|
||||
|
||||
if (sync && shouldSync) {
|
||||
|
||||
GBLogEx.info(min, `BASIC: Syncing changes for TABLE ${connectionName} ${tableName} keyword (${min.botId})...`);
|
||||
|
||||
await seq.sync({
|
||||
alter: true,
|
||||
alter: false,
|
||||
force: false // Keep it false due to data loss danger.
|
||||
});
|
||||
GBLogEx.info(min, `BASIC: Done sync for ${min.botId} ${connectionName} ${tableName} storage table...`);
|
||||
|
|
|
@ -973,6 +973,14 @@ export class KeywordsExpressions {
|
|||
}
|
||||
];
|
||||
|
||||
keywords[i++] = [
|
||||
/^\s*(FORMAT)(\s*)(.*)/gim,
|
||||
($0, $1, $2, $3) => {
|
||||
const params = this.getParams($3, ['value', 'format']);
|
||||
return `await dk.format({pid: pid, ${params}})`;
|
||||
}
|
||||
];
|
||||
|
||||
keywords[i++] = [
|
||||
/^\s*(send email)(\s*)(.*)/gim,
|
||||
($0, $1, $2, $3) => {
|
||||
|
|
Loading…
Add table
Reference in a new issue