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 = '
• Endzeit muss mindestens 1 Stunde nach der Startzeit liegen
+• Enddatum muss nach dem Startdatum liegen
• Maximaler Zeitraum: 1 Jahr (365 Tage)