From 995a4c64d8785c1d1c2410a950bdbdb583758e69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20X=2E=20F=C3=BCrst?= Date: Thu, 9 Apr 2026 09:26:18 +0200 Subject: [PATCH] Start/Ende-Datum ohne Zeit --- frontend/src/components/WeatherDashboard.jsx | 40 ++++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/frontend/src/components/WeatherDashboard.jsx b/frontend/src/components/WeatherDashboard.jsx index 5f4c0be..768f8fc 100644 --- a/frontend/src/components/WeatherDashboard.jsx +++ b/frontend/src/components/WeatherDashboard.jsx @@ -34,23 +34,23 @@ const WeatherDashboard = ({ data, currentData = [], rainData = [], timeRange = ' const savedRange = localStorage.getItem('customTimeRange') if (savedRange) { const { start, end } = JSON.parse(savedRange) - setCustomStartDate(start) - setCustomEndDate(end) + setCustomStartDate(start.split('T')[0]) + setCustomEndDate(end.split('T')[0]) } else { // Setze Standardwerte (letzte 7 Tage) const end = new Date() const start = new Date(end.getTime() - 7 * 24 * 60 * 60 * 1000) - setCustomStartDate(format(start, "yyyy-MM-dd'T'HH:mm")) - setCustomEndDate(format(end, "yyyy-MM-dd'T'HH:mm")) + setCustomStartDate(format(start, 'yyyy-MM-dd')) + setCustomEndDate(format(end, 'yyyy-MM-dd')) } } catch (e) { // Bei Fehler: Standardwerte verwenden const end = new Date() const start = new Date(end.getTime() - 7 * 24 * 60 * 60 * 1000) - setCustomStartDate(format(start, "yyyy-MM-dd'T'HH:mm")) - setCustomEndDate(format(end, "yyyy-MM-dd'T'HH:mm")) + setCustomStartDate(format(start, 'yyyy-MM-dd')) + setCustomEndDate(format(end, 'yyyy-MM-dd')) } setCustomError('') @@ -58,20 +58,15 @@ const WeatherDashboard = ({ data, currentData = [], rainData = [], timeRange = ' } const handleApplyCustomRange = () => { - // Validierung - const start = new Date(customStartDate) - const end = new Date(customEndDate) - if (!customStartDate || !customEndDate) { - setCustomError('Bitte Start- und Endzeit auswählen') + setCustomError('Bitte Start- und Enddatum auswählen') return } - const diffHours = (end - start) / (1000 * 60 * 60) - const diffDays = diffHours / 24 + const diffDays = Math.floor((new Date(customEndDate) - new Date(customStartDate)) / (1000 * 60 * 60 * 24)) - if (diffHours < 1) { - setCustomError('Endzeit muss mindestens 1 Stunde nach der Startzeit liegen') + if (diffDays < 0) { + setCustomError('Enddatum muss nach dem Startdatum liegen') return } @@ -80,6 +75,9 @@ const WeatherDashboard = ({ data, currentData = [], rainData = [], timeRange = ' return } + const startStr = customStartDate + 'T00:00' + const endStr = customEndDate + 'T23:59' + // Zeitbereich im localStorage speichern try { localStorage.setItem('customTimeRange', JSON.stringify({ @@ -92,7 +90,7 @@ const WeatherDashboard = ({ data, currentData = [], rainData = [], timeRange = ' } // Anwenden - onTimeRangeChange('custom', { start: customStartDate, end: customEndDate }) + onTimeRangeChange('custom', { start: startStr, end: endStr }) setShowCustomRangeModal(false) } @@ -927,9 +925,9 @@ const WeatherDashboard = ({ data, currentData = [], rainData = [], timeRange = '
- + setCustomStartDate(e.target.value)} @@ -937,9 +935,9 @@ const WeatherDashboard = ({ data, currentData = [], rainData = [], timeRange = '
- + setCustomEndDate(e.target.value)} @@ -951,7 +949,7 @@ const WeatherDashboard = ({ data, currentData = [], rainData = [], timeRange = ' )}
-

• Endzeit muss mindestens 1 Stunde nach der Startzeit liegen

+

• Enddatum muss nach dem Startdatum liegen

• Maximaler Zeitraum: 1 Jahr (365 Tage)