Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

256
Visualizações
Generating evenly split time stamps for every email in an array

I need to generate a send_at time that's divided evenly by the seconds in a working day 6am-6pm.

For the sake of this a list of 500 emails will be used.

var emailList = ["agent0@email.com", "agent1@email.com", "agent2@email.com", ...]; //List of 500 Emails
var currentTime = new Date().getTime(); //Unix Time Stamp for right now
var day = 86400/2; //12 hours in seconds(6am-6pm)
var interval = Math.ceil(day/emailList.length); // Every 86.4 second for 500 rounded to 87

I just can't figure out how to get past this point.

End Goal: I need a function that can take an input value of an array full of emails, divide that arrays.length by the 12 hour work day of 6am-6pm, and then output an array or object of times to send each email and maybe that email as well..

Input: myFuncton(emailList)

Output: [{email: "agent0@email.com", send_at: 1657559806}, {email: "agent1@email.com", send_at: 1657559893}, {email: "agent2@email.com", send_at: 1657559980}]

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Run over the array, adding each time the interval for the timestamp.

var emailList = ["agent0@email.com", "agent1@email.com", "agent2@email.com"];
var currentTime = new Date().getTime(); //Unix Time Stamp for right now
var day = 12 * 60 * 60 * 1000;
var interval = Math.ceil(day / emailList.length);

var result = [];
var send_at= currentTime;
emailList.forEach(function(email) {
  result.push({
    email: email,
    send_at: send_at,
    human_time: new Date(send_at)
  })
  send_at+= interval;
})
console.log(result)

about 4 years ago · Juan Pablo Isaza Relatório

0

You can note the startTime and endTime of the time window and then calculate the total timeSpan by subtracting them. Then divide the total time by the number of emails to calculate the intervalLength.

From that, you can calculate the send time for each email with the formula startTime + intervalLength * index

const emailList = Array(500).fill().map((_, i) => 'email_'+i); // Placeholder email list

const startTime = new Date().setHours(6, 0, 0, 0)
const endTime = new Date(startTime).setHours(18);

const timeSpan = endTime - startTime;
const intervalLength = timeSpan / emailList.length;

const output = emailList.map((email, i) => ({ email, send_at: startTime + intervalLength*i }));

console.log(output);

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda