From 8426bd1ae849ab8921dcac093b4ac9cec589f86b Mon Sep 17 00:00:00 2001 From: bartool Date: Wed, 12 Mar 2025 23:33:58 +0100 Subject: [PATCH] add parseWorkHours --- app/src/stores/WorkHoursStore.js | 40 +++++++++++++++++++++++++++++--- app/src/views/EditView.vue | 5 ++-- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/app/src/stores/WorkHoursStore.js b/app/src/stores/WorkHoursStore.js index ec11c80..b89ab6b 100644 --- a/app/src/stores/WorkHoursStore.js +++ b/app/src/stores/WorkHoursStore.js @@ -55,10 +55,14 @@ export const useWorkHoursStore = defineStore('workHours', () => { })), (newVal, oldVal) => { newVal.forEach((newEntry, index) => { - const oldEntry = oldVal[index]; + const oldEntry = oldVal?.[index]; + + if (!oldEntry) { + calculateWorkTime(workHours.value[index]); + } // Sprawdzamy, czy cokolwiek się zmieniło - if ( + else if ( newEntry.enterHour !== oldEntry.enterHour || newEntry.enterMinute !== oldEntry.enterMinute || newEntry.leaveHour !== oldEntry.leaveHour || @@ -90,10 +94,40 @@ export const useWorkHoursStore = defineStore('workHours', () => { workHours.value = []; } + const parseWorkHours = (userInput) => { + const lines = userInput.split('\n').map(line => line.trim()).filter(line => line); + const result = []; + + // przykładowa linia userInput: Marcin Nowak 21.02.2025 07:06:59 21.02.2025 15:58:04 08:51 + // const timeRegex = /(\d{2}\.\d{2}\.\d{4})\s(\d{2}):(\d{2}):\d{2}\s\d{2}\.\d{2}\.\d{4}\s(\d{2}):(\d{2}):\d{2}\s(\d{2}):(\d{2})/; + const timeRegex = /(\d{2})\.(\d{2})\.(\d{4})\s(\d{2}):(\d{2}):\d{2}\s\d{2}\.\d{2}\.\d{4}\s(\d{2}):(\d{2}):\d{2}\s(\d{2}):(\d{2})/; + + for (const line of lines) { + const match = line.match(timeRegex); + if (match) { + const [_, day, month, year, enterHour, enterMinute, leaveHour, leaveMinute, workHours, workMinutes] = match; + + const workDate = new Date(year, month - 1, day); + + result.push({ + date: workDate, + enterHour: parseInt(enterHour), + enterMinute: parseInt(enterMinute), + leaveHour: parseInt(leaveHour), + leaveMinute: parseInt(leaveMinute), + workHours: null, + workMinutes: null, + }); + } + } + + workHours.value = result; + } return { workHours, getDate, getWeekday, - clear + clear, + parseWorkHours } }) diff --git a/app/src/views/EditView.vue b/app/src/views/EditView.vue index f314e94..d04a624 100644 --- a/app/src/views/EditView.vue +++ b/app/src/views/EditView.vue @@ -113,12 +113,10 @@