diff --git a/frontend/src/utils/utils.js b/frontend/src/utils/utils.js index 4a3919d..29a66fa 100644 --- a/frontend/src/utils/utils.js +++ b/frontend/src/utils/utils.js @@ -153,14 +153,24 @@ function calculateDay(day) { // const exitTimes = [...day.exitTime] // If there's one more entry than exits, it means the user is currently clocked in. - if (day.entryTime.length > 0 && day.entryTime.length === day.exitTime.length + 1) { - const now = new Date() - const hh = String(now.getHours()).padStart(2, '0') - const mm = String(now.getMinutes()).padStart(2, '0') - const ss = String(now.getSeconds()).padStart(2, '0') - // Add the current time as the "exit" for the last entry. - day.exitTime.push(`${hh}:${mm}:${ss}`) + for (let i = 0; i < day.entryTime.length; i++) { + if (!day.exitTime[i] || typeof day.exitTime[i] !== 'string' || day.exitTime[i].trim() === '') { + const now = new Date() + const hh = String(now.getHours()).padStart(2, '0') + const mm = String(now.getMinutes()).padStart(2, '0') + const ss = String(now.getSeconds()).padStart(2, '0') + + day.exitTime[i] = `${hh}:${mm}:${ss}` + } } + // if (day.entryTime.length > 0 && day.entryTime.length === day.exitTime.length + 1) { + // const now = new Date() + // const hh = String(now.getHours()).padStart(2, '0') + // const mm = String(now.getMinutes()).padStart(2, '0') + // const ss = String(now.getSeconds()).padStart(2, '0') + // // Add the current time as the "exit" for the last entry. + // day.exitTime.push(`${hh}:${mm}:${ss}`) + // } if (day.entryTime.length === 0) { day.workedHours = 0