From 9bb7a71d86e269fa0a31cdc48f49eb9376453ba3 Mon Sep 17 00:00:00 2001 From: bartool Date: Thu, 30 Oct 2025 18:21:33 +0100 Subject: [PATCH] fix: update exit time handling in calculateDay function to ensure proper assignment --- frontend/src/utils/utils.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) 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