From 3e75a28a129f53385a1015e9b04461f718c77fed Mon Sep 17 00:00:00 2001 From: ashley Date: Fri, 4 Oct 2024 14:33:46 +0000 Subject: [PATCH] cool stuff --- src/libpoketube/init/pages-static.js | 46 ++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/libpoketube/init/pages-static.js b/src/libpoketube/init/pages-static.js index 76ea6a66..0fe158f2 100644 --- a/src/libpoketube/init/pages-static.js +++ b/src/libpoketube/init/pages-static.js @@ -153,6 +153,52 @@ module.exports = function (app, config, renderTemplate) { renderTemplate(res, req, "content-settings.ejs"); }); + + function gregorianToIslamic(gDate) { + const jd = Math.floor((gDate - new Date(1970, 0, 1)) / (24 * 60 * 60 * 1000)) + 2440588; + const islamicYear = Math.floor((30 * (jd - 1948440) + 10646) / 10631); + return islamicYear; +} + + function gregorianToPersian(gDate) { + const persianEpoch = 226895; // Julian Day of Persian Epoch + const jd = Math.floor((gDate - new Date(1970, 0, 1)) / (24 * 60 * 60 * 1000)) + 2440588; + const persianYear = Math.floor((jd - persianEpoch) / 365.2421985) + 1; + return persianYear; +} + +app.get('/calendar', (req, res) => { + const queryDate = req.query.date ? new Date(req.query.date) : new Date(); + const weekOffset = parseInt(req.query.week) || 0; + + const currentDate = new Date(queryDate); + currentDate.setDate(currentDate.getDate() + weekOffset * 7); + + const year = currentDate.getFullYear(); + const month = currentDate.getMonth(); + const startOfWeek = new Date(currentDate); + startOfWeek.setDate(currentDate.getDate() - currentDate.getDay()); + + const days = Array.from({ length: 7 }, (_, i) => { + const day = new Date(startOfWeek); + day.setDate(startOfWeek.getDate() + i); + return day; + }); + + const islamicYear = gregorianToIslamic(currentDate); + const persianYear = gregorianToPersian(currentDate); + + renderTemplate(res, req, "calendar.ejs", { + year, + islamicYear, + persianYear, + month, + currentDate, + days, + }); +}); + + app.get("/offline", function (req, res) { res.sendFile("offline.html", { root: location_pwa }); });