Idk who tf is duplicating the sheets
This commit is contained in:
@@ -22,8 +22,6 @@ export default async function parseV1V2(downloadedFilePath) {
|
||||
await workbook.xlsx.readFile(downloadedFilePath);
|
||||
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;
|
||||
|
||||
// Get today's date for comparison
|
||||
@@ -34,18 +32,37 @@ export default async function parseV1V2(downloadedFilePath) {
|
||||
|
||||
const today = getCurrentDateObject();
|
||||
|
||||
const upcomingSheets = sheetNames.filter((name) => {
|
||||
const match = name.match(dateRegex);
|
||||
if (!match) return false;
|
||||
const datedSheets = [];
|
||||
|
||||
const day = Number.parseInt(match[2], 10);
|
||||
const month = Number.parseInt(match[3], 10) - 1; // JavaScript months are 0-indexed
|
||||
const year = Number.parseInt(match[4], 10);
|
||||
for (const sheet of workbook.worksheets) {
|
||||
const match = sheet.name.match(dateRegex);
|
||||
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);
|
||||
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 = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user