• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

211
Vistas
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}]

almost 3 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

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)

almost 3 years ago · Juan Pablo Isaza Denunciar

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);

almost 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda