Start/Ende-Datum ohne Zeit
This commit is contained in:
@@ -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 = '
|
||||
|
||||
<div className="modal-form">
|
||||
<div className="form-group">
|
||||
<label htmlFor="startDate">Startzeit:</label>
|
||||
<label htmlFor="startDate">Startdatum:</label>
|
||||
<input
|
||||
type="datetime-local"
|
||||
type="date"
|
||||
id="startDate"
|
||||
value={customStartDate}
|
||||
onChange={(e) => setCustomStartDate(e.target.value)}
|
||||
@@ -937,9 +935,9 @@ const WeatherDashboard = ({ data, currentData = [], rainData = [], timeRange = '
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label htmlFor="endDate">Endzeit:</label>
|
||||
<label htmlFor="endDate">Enddatum:</label>
|
||||
<input
|
||||
type="datetime-local"
|
||||
type="date"
|
||||
id="endDate"
|
||||
value={customEndDate}
|
||||
onChange={(e) => setCustomEndDate(e.target.value)}
|
||||
@@ -951,7 +949,7 @@ const WeatherDashboard = ({ data, currentData = [], rainData = [], timeRange = '
|
||||
)}
|
||||
|
||||
<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>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user