const makeTimes = (interval, elapsedTimeMin) => {
const deltaTimeMin = Math.ceil(elapsedTimeMin / 30) * 30;
const startTime = new Date(interval.start);
const endTime = new Date(interval.end);
if (startTime.getSeconds() > 0) {
startTime.setSeconds(60);
}
startTime.setMinutes(Math.ceil(startTime.getMinutes() / 30) * 30);
const result = [];
while (startTime <= endTime) {
result.push(startTime.toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit' }));
startTime.setMinutes(startTime.getMinutes() + deltaTimeMin);
}
return result;
}
makeTimes({start: 'Tue Aug 30 2022 09:00:00', end: 'Tue Aug 30 2022 16:30:00'}, 20);
// Array(16) [ "09:00", "09:30", "10:00", "10:30", "11:00", "11:30", "12:00", "12:30", "13:00", "13:30", … ]
makeTimes({start: 'Tue Aug 30 2022 09:00:00', end: 'Tue Aug 30 2022 16:30:00'}, 40);
// Array(8) [ "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00" ]