mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-15 07:58:19 +01:00
woaw stuff
This commit is contained in:
parent
d5dd9303b8
commit
27ae6acc87
1 changed files with 13 additions and 16 deletions
|
@ -169,31 +169,28 @@ 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 currentDate = new Date(queryDate);
|
const year = queryDate.getFullYear();
|
||||||
currentDate.setDate(currentDate.getDate() + weekOffset * 7);
|
const month = queryDate.getMonth();
|
||||||
|
|
||||||
const year = currentDate.getFullYear();
|
const firstDay = new Date(year, month, 1);
|
||||||
const month = currentDate.getMonth();
|
const firstDayWeekday = firstDay.getDay();
|
||||||
const startOfWeek = new Date(currentDate);
|
|
||||||
startOfWeek.setDate(currentDate.getDate() - currentDate.getDay());
|
|
||||||
|
|
||||||
const days = Array.from({ length: 7 }, (_, i) => {
|
const totalDays = new Date(year, month + 1, 0).getDate();
|
||||||
const day = new Date(startOfWeek);
|
|
||||||
day.setDate(startOfWeek.getDate() + i);
|
const days = Array.from({ length: 42 }, (_, i) => {
|
||||||
return day;
|
const day = new Date(year, month, i - firstDayWeekday + 1);
|
||||||
|
return (day.getMonth() === month) ? day : null;
|
||||||
});
|
});
|
||||||
|
|
||||||
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,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue