From ea3a3fc12c76c68ddb437f8e9a95b2f9ff8550aa Mon Sep 17 00:00:00 2001 From: Kerim Atilgan Date: Fri, 15 May 2026 16:10:50 +0200 Subject: [PATCH] Unify date display to DD.MM.YYYY across the UI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously two formats showed up next to each other: raw ISO (YYYY-MM-DD) where DB values were interpolated directly, and toLocaleDateString('de-DE') output (D.M.YYYY without leading zeros) where formatDate was used. - formatDate / formatDateTime now build the string explicitly with zero-padded day and month, so dates render as DD.MM.YYYY (and DD.MM.YYYY HH:MM for timestamps) regardless of locale. - Replaced the remaining raw uses (Anbieter-Admin createdAt, Mitarbeiter-Prozentsätze gueltig_ab, the new Benutzer tab's createdAt, PDF export date filters and footer). - Native fields are unchanged — they require the ISO value internally and render localized in the picker. --- public/script.js | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/public/script.js b/public/script.js index 45a2850..48a3de4 100644 --- a/public/script.js +++ b/public/script.js @@ -601,9 +601,16 @@ async function loadSchaltungen() { } } +// Format any ISO-like date string (YYYY-MM-DD or full timestamp) as DD.MM.YYYY +// with leading zeros. Returns the original string unchanged if it cannot be parsed. function formatDate(dateString) { + if (!dateString) return ''; const date = new Date(dateString); - return date.toLocaleDateString('de-DE'); + if (isNaN(date.getTime())) return String(dateString); + const dd = String(date.getDate()).padStart(2, '0'); + const mm = String(date.getMonth() + 1).padStart(2, '0'); + const yyyy = date.getFullYear(); + return `${dd}.${mm}.${yyyy}`; } async function showDocuments(schaltungId) { @@ -848,7 +855,7 @@ async function loadAnbieterAdmin() { } anbieter.forEach(a => { - const createdAt = new Date(a.created_at).toLocaleDateString('de-DE'); + const createdAt = formatDate(a.created_at); const tr = document.createElement('tr'); tr.innerHTML = ` ${a.id} @@ -1844,8 +1851,15 @@ async function loadGeloeschteSchaltungen() { } function formatDateTime(dateTimeString) { - const date = new Date(dateTimeString); - return date.toLocaleDateString('de-DE') + ' ' + date.toLocaleTimeString('de-DE', {hour: '2-digit', minute: '2-digit'}); + if (!dateTimeString) return ''; + const d = new Date(dateTimeString); + if (isNaN(d.getTime())) return String(dateTimeString); + const dd = String(d.getDate()).padStart(2, '0'); + const mm = String(d.getMonth() + 1).padStart(2, '0'); + const yyyy = d.getFullYear(); + const HH = String(d.getHours()).padStart(2, '0'); + const MM = String(d.getMinutes()).padStart(2, '0'); + return `${dd}.${mm}.${yyyy} ${HH}:${MM}`; } // Filter functionality @@ -3096,7 +3110,7 @@ async function loadMitarbeiterProzentsaetzeAdmin() {
${escapeHtml(String(p.prozentsatz))}% ${p.beschreibung ? `- ${escapeHtml(p.beschreibung)}` : ''} -
Gültig ab: ${escapeHtml(p.gueltig_ab)} +
Gültig ab: ${escapeHtml(formatDate(p.gueltig_ab))}