redesign calendar api

This commit is contained in:
isUnknown 2024-09-11 15:17:44 +02:00
parent 4b6b61f762
commit 78d542cbac
3 changed files with 134 additions and 5 deletions

View file

@ -146,19 +146,48 @@ function getId(eventData) {
return id;
}
function createEmptyCalendar() {
const calendar = {};
for (let month = 9; month < 19; month++) {
const normalizedMonth = ((month - 1) % 12) + 1;
const daysInMonth = dayjs()
.month(normalizedMonth - 1)
.daysInMonth();
calendar[normalizedMonth] = {
name: dayjs()
.month(normalizedMonth - 1)
.format("MMMM"),
};
for (let day = 1; day <= daysInMonth; day++) {
calendar[normalizedMonth][day] = null;
}
}
return calendar;
}
async function getMergedDates(monthNumb, dates) {
const month = dayjs().month(monthNumb).format("YYYY-MM");
const calendar = createEmptyCalendar();
const requestParams = {
month,
dates,
calendar,
};
const requestOptions = {
method: "POST",
body: JSON.stringify(requestParams),
};
const response = await fetch("/month-dates.json", requestOptions);
const response = await fetch(
"/get-current-season-calendar.json",
requestOptions
);
const json = await response.json();
console.log("calendar", json);
return json;
}