From 50baefabfe167ae867d65ef96298edea35786bc7 Mon Sep 17 00:00:00 2001 From: minie4 Date: Wed, 1 Jun 2022 18:37:46 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20lessons=20spanning=20over?= =?UTF-8?q?=20more=20than=20two=20lessons?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/parser/untis.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/parser/untis.js b/server/parser/untis.js index bc3fbef..851cf45 100644 --- a/server/parser/untis.js +++ b/server/parser/untis.js @@ -58,8 +58,18 @@ export function parseSubstitutionPlan(html) { rowData[columntitle] = cleantext; }); + // Split change if it spans over multiple lessons const rawLesson = rowData.lesson; - const lessons = rawLesson.match(/\d+/g).map(Number); + const fromToLessons = rawLesson.match(/\d+/g).map(Number); + const from = fromToLessons[0]; + const to = fromToLessons[1] || fromToLessons[0]; + + // Generate numbers from `from` to `to` + const lessons = Array(to - from + 1) + .fill() + .map((_e, i) => i + from); + + // Create new change for each lesson the change spans over for (const lesson of lessons) { rowData.lesson = lesson; data.push({ ...rowData });