Start/Ende-Datum ohne Zeit

This commit is contained in:
2026-04-09 09:26:18 +02:00
parent 6c45f260c6
commit 995a4c64d8

View File

@@ -34,23 +34,23 @@ const WeatherDashboard = ({ data, currentData = [], rainData = [], timeRange = '
const savedRange = localStorage.getItem('customTimeRange') const savedRange = localStorage.getItem('customTimeRange')
if (savedRange) { if (savedRange) {
const { start, end } = JSON.parse(savedRange) const { start, end } = JSON.parse(savedRange)
setCustomStartDate(start) setCustomStartDate(start.split('T')[0])
setCustomEndDate(end) setCustomEndDate(end.split('T')[0])
} else { } else {
// Setze Standardwerte (letzte 7 Tage) // Setze Standardwerte (letzte 7 Tage)
const end = new Date() const end = new Date()
const start = new Date(end.getTime() - 7 * 24 * 60 * 60 * 1000) const start = new Date(end.getTime() - 7 * 24 * 60 * 60 * 1000)
setCustomStartDate(format(start, "yyyy-MM-dd'T'HH:mm")) setCustomStartDate(format(start, 'yyyy-MM-dd'))
setCustomEndDate(format(end, "yyyy-MM-dd'T'HH:mm")) setCustomEndDate(format(end, 'yyyy-MM-dd'))
} }
} catch (e) { } catch (e) {
// Bei Fehler: Standardwerte verwenden // Bei Fehler: Standardwerte verwenden
const end = new Date() const end = new Date()
const start = new Date(end.getTime() - 7 * 24 * 60 * 60 * 1000) const start = new Date(end.getTime() - 7 * 24 * 60 * 60 * 1000)
setCustomStartDate(format(start, "yyyy-MM-dd'T'HH:mm")) setCustomStartDate(format(start, 'yyyy-MM-dd'))
setCustomEndDate(format(end, "yyyy-MM-dd'T'HH:mm")) setCustomEndDate(format(end, 'yyyy-MM-dd'))
} }
setCustomError('') setCustomError('')
@@ -58,20 +58,15 @@ const WeatherDashboard = ({ data, currentData = [], rainData = [], timeRange = '
} }
const handleApplyCustomRange = () => { const handleApplyCustomRange = () => {
// Validierung
const start = new Date(customStartDate)
const end = new Date(customEndDate)
if (!customStartDate || !customEndDate) { if (!customStartDate || !customEndDate) {
setCustomError('Bitte Start- und Endzeit auswählen') setCustomError('Bitte Start- und Enddatum auswählen')
return return
} }
const diffHours = (end - start) / (1000 * 60 * 60) const diffDays = Math.floor((new Date(customEndDate) - new Date(customStartDate)) / (1000 * 60 * 60 * 24))
const diffDays = diffHours / 24
if (diffHours < 1) { if (diffDays < 0) {
setCustomError('Endzeit muss mindestens 1 Stunde nach der Startzeit liegen') setCustomError('Enddatum muss nach dem Startdatum liegen')
return return
} }
@@ -80,6 +75,9 @@ const WeatherDashboard = ({ data, currentData = [], rainData = [], timeRange = '
return return
} }
const startStr = customStartDate + 'T00:00'
const endStr = customEndDate + 'T23:59'
// Zeitbereich im localStorage speichern // Zeitbereich im localStorage speichern
try { try {
localStorage.setItem('customTimeRange', JSON.stringify({ localStorage.setItem('customTimeRange', JSON.stringify({
@@ -92,7 +90,7 @@ const WeatherDashboard = ({ data, currentData = [], rainData = [], timeRange = '
} }
// Anwenden // Anwenden
onTimeRangeChange('custom', { start: customStartDate, end: customEndDate }) onTimeRangeChange('custom', { start: startStr, end: endStr })
setShowCustomRangeModal(false) setShowCustomRangeModal(false)
} }
@@ -927,9 +925,9 @@ const WeatherDashboard = ({ data, currentData = [], rainData = [], timeRange = '
<div className="modal-form"> <div className="modal-form">
<div className="form-group"> <div className="form-group">
<label htmlFor="startDate">Startzeit:</label> <label htmlFor="startDate">Startdatum:</label>
<input <input
type="datetime-local" type="date"
id="startDate" id="startDate"
value={customStartDate} value={customStartDate}
onChange={(e) => setCustomStartDate(e.target.value)} onChange={(e) => setCustomStartDate(e.target.value)}
@@ -937,9 +935,9 @@ const WeatherDashboard = ({ data, currentData = [], rainData = [], timeRange = '
</div> </div>
<div className="form-group"> <div className="form-group">
<label htmlFor="endDate">Endzeit:</label> <label htmlFor="endDate">Enddatum:</label>
<input <input
type="datetime-local" type="date"
id="endDate" id="endDate"
value={customEndDate} value={customEndDate}
onChange={(e) => setCustomEndDate(e.target.value)} onChange={(e) => setCustomEndDate(e.target.value)}
@@ -951,7 +949,7 @@ const WeatherDashboard = ({ data, currentData = [], rainData = [], timeRange = '
)} )}
<div className="modal-info"> <div className="modal-info">
<p> Endzeit muss mindestens 1 Stunde nach der Startzeit liegen</p> <p> Enddatum muss nach dem Startdatum liegen</p>
<p> Maximaler Zeitraum: 1 Jahr (365 Tage)</p> <p> Maximaler Zeitraum: 1 Jahr (365 Tage)</p>
</div> </div>