Files
TIF22A_AnwProjekt_B/anwendung/src/components/DateElement.jsx
T
2023-05-04 12:33:20 +02:00

26 lines
895 B
React

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="dateElement round-border">
<p>{startDateString} - {endDateString}</p>
</div>
</>
);
}