getDay() não funciona no script


Preciso pegar o dia da semana no script, porém quando chega na função getDay() não fuciona.

Tem alguma forma de pegar o dia da semana no script?

Pode ser a posição de 0-6


5 comentários

Você tem que separar os dias da semana por vírgulas, por exemplo, a variável do meu bot é “workDays” e o valor é “0,1,2,3,4,5,6”


image

Teria com pegar o valor dessa variável no builder.js? Onde que faria a validação dos dias da semana?

Exemplo dias de funcionamento de 1,2,3.4,5?

Eu usei o código direto que tem disponível no bot atendimento humano. Acho que vale a pena dar uma olhada, pra te balizar. Você pode consultar ele nas ações do bloco que checam o funcionamento. O código é esse aqui:


//Default BLiP TimeZoneOffset = São Paulo (GMT-3)

var DEFAULT_OFFSET = 3;


// Receive the variables as parameters

function run(offset, start, end, workDays) {


offset = parseInt(offset) + DEFAULT_OFFSET;

let today = nowUTC(offset);
let startDate = utcDate(start, offset);
let endDate = utcDate(end, offset);

return ((today - startDate) > 0) && ((endDate - today) > 0) && isWorkDay(today, workDays);

}


//Get now UTC Date

function nowUTC(offset){

let now = new Date;

let utc_timestamp = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(),

now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds(), now.getUTCMilliseconds());


return new Date(utc_timestamp + offset * 3600 * 1000);

}


//Get UTC Date

function utcDate(timeString, offset){

let now = new Date;


let hour = getValueByString('hour', timeString);
let minutes = getValueByString('minutes', timeString)

hour += DEFAULT_OFFSET;

let utc_timestamp = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(),
hour, minutes, 0, 0);
return new Date(utc_timestamp + offset * 3600 * 1000);

}


//Get hour/minute by string with pattern HH:mm

function getValueByString(type, timeString){


if(type === 'hour'){
return parseInt(timeString.substring(0, timeString.indexOf(':')));
}

else if(type === 'minutes'){
return parseInt(timeString.substring(timeString.indexOf(':') + 1, timeString.length));
}

return 0;

}


//Get if today is a work day

function isWorkDay(today, workDays){

workDays = workDays.split(’,’);


return workDays.indexOf(today.getDay().toString()) >= 0;

}

Perfeito.

Só não identifiquei onde que vc consultou:



Você pode consultar ele nas ações do bloco que checam o funcionamento



Obrigado!

Olá @tiago.souza,


conseguiu fazer o que precisava?

Comente