Kalender Side Bar Bugfix

Noch etwas Bugfix + neue Funktionalität hinzugefügt :)
This commit is contained in:
AliGitGut
2023-05-22 23:49:01 +02:00
parent 4741ba6911
commit 2a87d54102
+13 -9
View File
@@ -4,10 +4,10 @@ const months = [["Januar", 31], ["Februar", 28], ["März", 31], ["April", 30], [
const days = months.map((month => month[1])) const days = months.map((month => month[1]))
let result = [] let result = []
let check = true let check = true
const weekdays = ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"] const weekdays = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"]
export default function BasicDateCalendar(p) { export default function BasicDateCalendar(p) {
if (check) { if (check) {
generateCalendar("01.11.2023", "15.01.2024") generateCalendar("01.12.2024", "15.09.2025")
check = false check = false
} }
return ( return (
@@ -16,6 +16,9 @@ export default function BasicDateCalendar(p) {
<div key={months} className={"A"}> <div key={months} className={"A"}>
<p>{getMonthName(index)}</p> <p>{getMonthName(index)}</p>
<div className={"Days"}> <div className={"Days"}>
{weekdays.map((weekday) => (
<p key={weekday}>{weekday}</p>
))}
{monthResult.map((date) => ( {monthResult.map((date) => (
<p key={date}>{date}</p> <p key={date}>{date}</p>
))} ))}
@@ -34,6 +37,7 @@ function getMonthName(monthIndex) {
} }
} }
function generateCalendar(start, ende) function generateCalendar(start, ende)
{ {
splitter(start, ende) splitter(start, ende)
@@ -45,8 +49,8 @@ function generateCalendar(start, ende)
for (let j = 1; j <= days[i]; j++) for (let j = 1; j <= days[i]; j++)
{ {
if ( if (
new Date(2023, i, j) >= new Date(2023, startParts[1] - 1, startParts[0]) && new Date(startParts[2], i, j) >= new Date(startParts[2], startParts[1] - 1, startParts[0]) &&
new Date(2023, i, j) <= new Date(2023, 11, 31) new Date(startParts[2], i, j) <= new Date(startParts[2], 11, 31)
) )
{ {
monthResult.push(j); monthResult.push(j);
@@ -60,7 +64,7 @@ function generateCalendar(start, ende)
let monthResultNewYear = []; let monthResultNewYear = [];
for (let g = 1; g <= days[h]; g++) for (let g = 1; g <= days[h]; g++)
{ {
if (new Date(2024, h, g) <= new Date(2024, endParts[1] - 1, endParts[0])) if (new Date(endParts[2], h, g) <= new Date(endParts[2], endParts[1] - 1, endParts[0]))
{ {
monthResultNewYear.push(g); monthResultNewYear.push(g);
} }
@@ -77,8 +81,8 @@ function generateCalendar(start, ende)
for (let j = 1; j <= days[i]; j++) for (let j = 1; j <= days[i]; j++)
{ {
if ( if (
new Date(2023, i, j) >= new Date(2023, startParts[1] - 1, startParts[0]) && new Date(startParts[2], i, j) >= new Date(startParts[2], startParts[1] - 1, startParts[0]) &&
new Date(2023, i, j) <= new Date(2023, endParts[1] - 1, endParts[0]) new Date(startParts[2], i, j) <= new Date(startParts[2], endParts[1] - 1, endParts[0])
) )
{ {
monthResult.push(j); monthResult.push(j);
@@ -92,7 +96,7 @@ function generateCalendar(start, ende)
function splitter(startDate, endDate) function splitter(startDate, endDate)
{ {
startParts = startDate.split(".") startParts = startDate.split(".")
//Test() //Transformer()
if (startParts[1][0] === 0) //prüft ob die erste Stelle des Monats eine 0 vorne stehen hat if (startParts[1][0] === 0) //prüft ob die erste Stelle des Monats eine 0 vorne stehen hat
{ {
startParts[1] = startParts[1][1] //überschreibt den Monat ohne die 0 startParts[1] = startParts[1][1] //überschreibt den Monat ohne die 0
@@ -104,7 +108,7 @@ function splitter(startDate, endDate)
} }
} }
function Test() function Transformer()
{ {
let formattedDateStr = startParts[1] + "/" + startParts[0] + "/" + startParts[2]; let formattedDateStr = startParts[1] + "/" + startParts[0] + "/" + startParts[2];
console.log(formattedDateStr) console.log(formattedDateStr)