added DateElement

This commit is contained in:
AlexE030
2023-05-02 15:36:03 +02:00
parent 04ca2319c2
commit 59b4f93930
+25
View File
@@ -0,0 +1,25 @@
function addDays(date, days) {
let result = new Date(date);
result.setDate(result.getDate() + days);
return result;
}
export default function DateElement(props){
let startDate;
let endDate;
const currDate = new Date();
startDate = addDays(currDate, (currDate.getDay()-1)*-1); //berechnet den Montag der aktuellen Woche
startDate = addDays(startDate, props.week*7); //erhöht das Datum um 7 Tage für jede Woche, die weiter geklickt wurde.
endDate = addDays(startDate, 6);
const startDateString = `${startDate.getDate()}.${startDate.getMonth()+1}.${startDate.getFullYear()}`;
const endDateString = `${endDate.getDate()}.${endDate.getMonth()+1}.${endDate.getFullYear()}`;
return (
<>
<div className="container">
<p className="dateElement">{startDateString} - {endDateString}</p>
</div>
</>
);
}