'How to return epoch of all midnights in given time span?

I have a time span between two epoch times (in seconds). I want a function that returns the epoch times (in seconds) of all midnights within that time span.

In pseudocode I would want something like this:

const epoch_start = 1600000;
const epoch_end = 16040000;

function getMidnights(start, end){
    // do your magic    
}

console.log(getMidnights(epoch_start, epoch_end));

I would expect the return of that function to look like this: [1600020, 1600400] (these are just example values).

What would be the most efficient way to do this?

My ideas were: get unique list of days within range and return their midnight.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source