Trainingstag aus .env

This commit is contained in:
klaas 2024-10-01 21:56:09 +02:00
parent 7dc599f11b
commit 58c0f55c7c
2 changed files with 8 additions and 5 deletions

View File

@ -6,4 +6,6 @@ MAILFROM=
MAILPASS=
PORT=2000
TELEBOT=
TELECHAT=
TELECHAT=
HOST=
WEEKDAY=4

9
app.js
View File

@ -157,11 +157,12 @@ const addNewSpiel = async (spielName) => {
}
};
function getThursdayOfWeek(week, year) {
function getdayOfWeek(week, year) {
const weekday = parseInt(process.env.WEEKDAY, 10);
const firstDayOfYear = new Date(year, 0, 1);
const dayOfWeek = firstDayOfYear.getDay();
const daysUntilFirstThursday =
dayOfWeek <= 4 ? 4 - dayOfWeek : 11 - dayOfWeek;
dayOfWeek <= weekday ? weekday - dayOfWeek : 11 - dayOfWeek;
const daysUntilThursdayOfWeek = (week - 1) * 7 + daysUntilFirstThursday;
const thursdayOfWeek = new Date(year, 0, 1 + daysUntilThursdayOfWeek);
return thursdayOfWeek;
@ -677,7 +678,7 @@ app.get("/training", requireAuth, async (req, res) => {
);
const trainingsDates = trainingsResult.rows.map((tr) => ({
kw: tr.kw,
datum: formatDate(getThursdayOfWeek(tr.kw, tr.jahr)),
datum: formatDate(getdayOfWeek(tr.kw, tr.jahr)),
}));
// Vorheriges Training ermitteln
@ -737,7 +738,7 @@ ORDER BY r.riegennummer, t.geburtsdatum ASC;
});
if (training) {
training.datum = getThursdayOfWeek(training.kw, training.jahr);
training.datum = getdayOfWeek(training.kw, training.jahr);
}
const aufwaermleiterCandidates = await getCandidatesForAufwaermleiter();