1
0

fix: Duplicates
All checks were successful
Remote Deploy / deploy (push) Successful in 5s

Idk who tf is duplicating the sheets
This commit is contained in:
2026-01-13 09:48:59 +01:00
parent 4da178d227
commit c34f4ee1d1

View File

@@ -22,8 +22,6 @@ export default async function parseV1V2(downloadedFilePath) {
await workbook.xlsx.readFile(downloadedFilePath); await workbook.xlsx.readFile(downloadedFilePath);
const teacherMap = await parseTeachers(); const teacherMap = await parseTeachers();
const sheetNames = workbook.worksheets.map((sheet) => sheet.name);
const dateRegex = /^(pondělí|úterý|středa|čtvrtek|pátek|po|út|ut|st|čt|ct|pa|pá)\s+(\d{1,2})\.\s*(\d{1,2})\.\s*(20\d{2})/i; const dateRegex = /^(pondělí|úterý|středa|čtvrtek|pátek|po|út|ut|st|čt|ct|pa|pá)\s+(\d{1,2})\.\s*(\d{1,2})\.\s*(20\d{2})/i;
// Get today's date for comparison // Get today's date for comparison
@@ -34,18 +32,37 @@ export default async function parseV1V2(downloadedFilePath) {
const today = getCurrentDateObject(); const today = getCurrentDateObject();
const upcomingSheets = sheetNames.filter((name) => { const datedSheets = [];
const match = name.match(dateRegex);
if (!match) return false;
const day = Number.parseInt(match[2], 10); for (const sheet of workbook.worksheets) {
const month = Number.parseInt(match[3], 10) - 1; // JavaScript months are 0-indexed const match = sheet.name.match(dateRegex);
const year = Number.parseInt(match[4], 10); if (!match) continue;
const day = parseInt(match[2], 10);
const month = parseInt(match[3], 10) - 1;
const year = parseInt(match[4], 10);
const sheetDate = new Date(year, month, day); const sheetDate = new Date(year, month, day);
if (sheetDate < today) continue;
return sheetDate >= today; const dateKey = `${year}-${month + 1}-${day}`;
})
datedSheets.push({
sheet,
dateKey,
});
}
const sheetsByDate = {};
for (const item of datedSheets) {
sheetsByDate[item.dateKey] ??= [];
sheetsByDate[item.dateKey].push(item.sheet);
}
const upcomingSheets = Object.values(sheetsByDate).map((sheets) => {
if (sheets.length === 1) return sheets[0].name;
return (sheets.find((s) => s.state !== "hidden") ?? sheets[0]).name;
});
const final = []; const final = [];