In Javascript (and in most languages, actually), dates and times are represented in memory as the amount of milliseconds since an arbitrary date-time. You can see this number by using the getTime function of type Date, like this:
var agora = new Date();
agora.getTime();
So, to find out how long a call took, you can do the following:
var horaEntrada = foo;
var horaSaida = bar;
var tempoAtendimentoEmMilissegundos = bar.getTime() - foo.getTime();
Just change foo
and bar
to the actual in and out times.
If you want to convert the service time to other units of measure, it is easy:
var tempoAtendimentoEmSegundos = tempoAtendimentoEmMilissegundos / 1000;
var tempoAtendimentoEmMinutos = tempoAtendimentoEmSegundos / 60;
// etc., etc.
Finally, to get the average, just make a simple account. Accumulate all times in one sum, and divide the sum by the number of calls.
var soma = 0;
for (let i = 0; i < tempos.length; i++) {
soma += tempos[i];
}
var media = soma / tempos.length;