Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!