Skip to content

Commit

Permalink
fix(basic.gblib): Correct web automation 'date' use.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanPerdomo committed Apr 5, 2023
1 parent db7ed36 commit 4809fec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions packages/basic.gblib/services/DialogKeywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -906,14 +906,23 @@ export class DialogKeywords {
);
};

const value = extractEntity(answer);
const parseDate = str => {
function pad(x){return (((''+x).length==2) ? '' : '0') + x; }
var m = str.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/)
, d = (m) ? new Date(m[3], m[2]-1, m[1]) : null
, matchesPadded = (d&&(str==[pad(d.getDate()),pad(d.getMonth()+1),d.getFullYear()].join('/')))
, matchesNonPadded = (d&&(str==[d.getDate(),d.getMonth()+1,d.getFullYear()].join('/')));
return (matchesPadded || matchesNonPadded) ? d : null;
}

if (value === null || value.length != 1) {
let value = parseDate(answer);

if (value === null) {
await this.talk({ pid, text: 'Por favor, digite uma data no formato 12/12/2020.' });
return await this.hear({ pid, kind, args });
}

result = value;
value = new Date(value);
result = value.toLocaleString('pt-BR', { day: '2-digit', month: '2-digit', year: 'numeric' });
} else if (kind === 'hour') {
const extractEntity = (text: string) => {
return text.match(/^([0-1]?[0-9]|2[0-4]):([0-5][0-9])(:[0-5][0-9])?$/gi);
Expand Down
2 changes: 1 addition & 1 deletion packages/basic.gblib/services/SystemKeywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ export class SystemKeywords {

// Processes FILTER option to ensure parallel SET calls.

const filter = await DialogKeywords.getOption({ pid, name });
const filter = await DialogKeywords.getOption({ pid, name: 'filter' });
if (filter) {
const row = this.find({ pid, handle: null, args: [filter] });
address += row['line'];
Expand Down

0 comments on commit 4809fec

Please sign in to comment.