I'm currently working on a break reminder. Users will be able to set start and end times which I will compare to the current times to determine when to trigger a break notification.
const currentDate = new Date();
let startTime = "09:00:00";
let endTime = "17:00:00";
const startTimeSplit = startTime.split(":");
const endTimeSplit = endTime.split(":");
const startDate = new Date();
startDate.setHours(parseInt(startTimeSplit[0], 10));
startDate.setMinutes(parseInt(startTimeSplit[1], 10));
startDate.setSeconds(0);
const endDate = new Date();
endDate.setDate(startDate.getDate() + 1)
endDate.setHours(parseInt(endTimeSplit[0], 10));
endDate.setMinutes(parseInt(endTimeSplit[1], 10));
endDate.setSeconds(0);
if (startDate <= currentDate && endDate > currentDate && this.checkNonBreakTime()) {
const timeDelta = (currentDate.getTime() - startDate.getTime()) / 60000;
if (timeDelta % frequency === 0) {
this.createNotification();
}
}
The start and end time variables are coming from a DB based on agents' preferences.
The issue here is that if the end time is potentially the next day, my code breaks.
Has anyone built a similar reminder app before and have an idea how I can go about comparing the 3 dates?