add parseWorkHours
This commit is contained in:
@@ -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
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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 = () => {
|
||||
|
||||
Reference in New Issue
Block a user