What is the best way to calculate time intervals (with or without some lib)?
Case:
I have three parameters:
startTime
is an instance of Date
;
endTime
an instance of Date
;
interval
is of type "number"
;
Passing these parameters to some function, I expect an array of Date
instances with the date of the intervals.
Example:
const startDateTime = new Date(2022, 1, 1);
startDateTime.setHours(9, 0, 0, 0);
const endDateTime = new Date(2022, 1, 1);
endDateTime.setHours(10, 30, 0, 0);
calculateDateTimeIntervals(startTime, endTime, 1800) //the last param is the time interval in seconds: 1800 is 30min
//expect array Date in time format to simplify: ['09:00', '09:30', '10:00', '10:30'];