I'm creating a custom function where I would like to update the start time of a schedule depending if they had Overtime.
For example, Employee1 entire schedule is from 8:45 AM - 7:00 PM, however this person had Overtime before his real shift started, so I'm trying to update his start time based on that, but when I try to compare the start time with the Overtime start time, for some reason even when they both are equal, the script doesn't recognize them, below my code:
function calculateStart(shiftStart, shiftEnd, scheduleState, scheduleStateStart, scheduleStateEnd) {
var newScheduleState = [];
var res;
var newShiftStart = "Start";
var sLen = scheduleState.length;
//Creating new array that contains only the schedule information for one day
for (i = 0; i < sLen; i++) {
res = String(scheduleState[i]).slice(0, 3);
if(res != "Req"){
newScheduleState.push(scheduleState[i]);
}else{
break;
}
}
//Checkig if shiftStart needs to be updated based on Overtime
sLen = newScheduleState.length;
for (i = 0; i < sLen; i++){
if(String(newScheduleState[i]) === "Overtime"){
newShiftStart = "Yes, this is overtime";
//NOT SURE WHY the next line is false
if(shiftStart == scheduleStateStart[i]){
newShiftStart = "Yes, they are the same" + shiftStart + ' - ' + scheduleStateStart[i];
if(String(newScheduleState[i+1]) === "CLINIC"){
newShiftStart = "End Clinic"
//newShiftStart = scheduleStateEnd[i+1];
}else{
newShiftStart = "Overtime"
//newShiftStart = scheduleStateEnd[i];
}
}else{
newShiftStart = "Not the same " + shiftStart + ' --- ' + scheduleStateStart[i];
}
}
}
return newShiftStart;
// Returns: Not the same Sat Dec 30 1899 09:47:04 GMT-0500 (GMT-05:00) --- Sat Dec 30 1899 20:02:04 GMT-0500 (GMT-05:00)
}
And below and image of the parameters:
Adding a link to sample file here