Enhance event date normalization: Introduce a helper function to standardize date formats for the event form, ensuring consistent input handling. Update event data initialization to utilize this function, improving data integrity and user experience.
All checks were successful
Deploy miriamgemeinde / deploy (push) Successful in 6s

This commit is contained in:
Torsten Schulz (local)
2026-04-29 16:16:16 +02:00
parent 8bd5da35a9
commit a2b1ebdb97

View File

@@ -113,6 +113,31 @@ import Multiselect from 'vue-multiselect';
import { formatTime } from '@/utils/strings'; import { formatTime } from '@/utils/strings';
import AddImageDialog from '@/components/AddImageDialog.vue'; import AddImageDialog from '@/components/AddImageDialog.vue';
function normalizeDateForInput(value) {
if (!value) return '';
if (value instanceof Date && !Number.isNaN(value.getTime())) {
const yyyy = value.getFullYear();
const mm = String(value.getMonth() + 1).padStart(2, '0');
const dd = String(value.getDate()).padStart(2, '0');
return `${yyyy}-${mm}-${dd}`;
}
const raw = String(value).trim();
// ISO oder SQL-Format: YYYY-MM-DD...
const isoMatch = raw.match(/^(\d{4})-(\d{2})-(\d{2})/);
if (isoMatch) {
return `${isoMatch[1]}-${isoMatch[2]}-${isoMatch[3]}`;
}
// Deutsches Format: DD.MM.YYYY
const deMatch = raw.match(/^(\d{1,2})\.(\d{1,2})\.(\d{4})$/);
if (deMatch) {
const dd = String(deMatch[1]).padStart(2, '0');
const mm = String(deMatch[2]).padStart(2, '0');
const yyyy = deMatch[3];
return `${yyyy}-${mm}-${dd}`;
}
return '';
}
export default { export default {
name: 'EventForm', name: 'EventForm',
components: { Multiselect, AddImageDialog }, components: { Multiselect, AddImageDialog },
@@ -140,7 +165,10 @@ export default {
}, },
data() { data() {
return { return {
eventData: { ...this.event }, eventData: {
...this.event,
date: normalizeDateForInput(this.event?.date),
},
selectedEventType: null, selectedEventType: null,
selectedInstitution: this.event.institution || null, selectedInstitution: this.event.institution || null,
selectedEventPlace: this.event.eventPlace || null, selectedEventPlace: this.event.eventPlace || null,
@@ -308,9 +336,7 @@ export default {
}, },
normalizeEventForForm(event) { normalizeEventForForm(event) {
const normalized = { ...(event || {}) }; const normalized = { ...(event || {}) };
if (typeof normalized.date === 'string') { normalized.date = normalizeDateForInput(normalized.date);
normalized.date = normalized.date.split('T')[0];
}
const dayValue = this.extractDayOfWeekValue(normalized.dayOfWeek); const dayValue = this.extractDayOfWeekValue(normalized.dayOfWeek);
if (dayValue > -1) { if (dayValue > -1) {
const mappedValue = dayValue === 0 ? 7 : dayValue; const mappedValue = dayValue === 0 ? 7 : dayValue;