add parseWorkHours

This commit is contained in:
2025-03-12 23:33:58 +01:00
parent b18296f8a8
commit 8426bd1ae8
2 changed files with 39 additions and 6 deletions

View File

@@ -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
}
})

View File

@@ -113,12 +113,10 @@
<script setup>
import TimeInputComponent from "@/components/TimeInputComponent.vue";
import { useWorkHoursStore } from "../stores/WorkHoursStore.js";
import { Modal } from 'bootstrap';
import { computed, watch, ref, onMounted } from "vue";
const rawText = ref("");
const storeWorkHours = useWorkHoursStore();
// const oldValue = ref(0);
const showButtons = ref(false);
onMounted(() => {
@@ -149,7 +147,8 @@ const getClassWeekday = (index) => {
}
const processInputText = () => {
console.log(rawText.value);
// console.log(rawText.value);
storeWorkHours.parseWorkHours(rawText.value);
}
const clearInput = () => {