1
0
Fork 0
mirror of https://codeberg.org/ashley/poke.git synced 2024-11-17 01:14:38 -05:00

woaw stuff

This commit is contained in:
ashley 2024-10-04 14:42:22 +00:00
parent d5dd9303b8
commit 27ae6acc87

View file

@ -168,32 +168,29 @@ module.exports = function (app, config, renderTemplate) {
} }
app.get('/calendar', (req, res) => { app.get('/calendar', (req, res) => {
const queryDate = req.query.date ? new Date(req.query.date) : new Date(); const queryDate = req.query.date ? new Date(req.query.date) : new Date();
const weekOffset = parseInt(req.query.week) || 0;
const year = queryDate.getFullYear();
const month = queryDate.getMonth();
const currentDate = new Date(queryDate); const firstDay = new Date(year, month, 1);
currentDate.setDate(currentDate.getDate() + weekOffset * 7); const firstDayWeekday = firstDay.getDay();
const year = currentDate.getFullYear(); const totalDays = new Date(year, month + 1, 0).getDate();
const month = currentDate.getMonth();
const startOfWeek = new Date(currentDate);
startOfWeek.setDate(currentDate.getDate() - currentDate.getDay());
const days = Array.from({ length: 7 }, (_, i) => { const days = Array.from({ length: 42 }, (_, i) => {
const day = new Date(startOfWeek); const day = new Date(year, month, i - firstDayWeekday + 1);
day.setDate(startOfWeek.getDate() + i); return (day.getMonth() === month) ? day : null;
return day;
}); });
const islamicYear = gregorianToIslamic(currentDate); const islamicYear = gregorianToIslamic(queryDate);
const persianYear = gregorianToPersian(currentDate); const persianYear = gregorianToPersian(queryDate);
renderTemplate(res, req, "calendar.ejs", { renderTemplate(res, req, "calendar.ejs", {
year, year,
islamicYear, islamicYear,
persianYear, persianYear,
month, currentDate: queryDate,
currentDate,
days, days,
}); });
}); });