fix: "Ad 6,7" in absences
This commit is contained in:
@@ -9,6 +9,16 @@ export const isTeacherToken = (t) => /^[A-Za-z]+$/.test(t);
|
||||
export const parseSpec = (spec) => {
|
||||
if (!spec) return null;
|
||||
let m;
|
||||
|
||||
// Handle "6,7"
|
||||
if ((m = spec.match(/^(\d+),(\d+)$/))) {
|
||||
const from = Number(m[1]);
|
||||
const to = Number(m[2]);
|
||||
return from >= 1 && to >= from && to <= LAST_HOUR
|
||||
? { kind: "range", value: { from, to } }
|
||||
: null;
|
||||
}
|
||||
|
||||
if ((m = spec.match(/^(\d+)\+$/))) {
|
||||
const from = Number(m[1]);
|
||||
return from >= 1 && from <= LAST_HOUR
|
||||
@@ -50,18 +60,15 @@ const processTeacherList = (teacherListStr, spec, teacherMap) => {
|
||||
let results = [];
|
||||
|
||||
if (teacherListStr.includes(",")) {
|
||||
// Comma = spec applies to all
|
||||
const teachers = teacherListStr.split(/\s*,\s*/).filter(Boolean);
|
||||
results = teachers.map((t) => makeResult(t, spec, teacherMap));
|
||||
} else if (teacherListStr.includes(";")) {
|
||||
// Semicolon = spec applies only to last, others = whole day
|
||||
const teachers = teacherListStr.split(/\s*;\s*/).filter(Boolean);
|
||||
teachers.forEach((t, i) => {
|
||||
const resSpec = i === teachers.length - 1 ? spec : null;
|
||||
results.push(makeResult(t, resSpec, teacherMap));
|
||||
});
|
||||
} else {
|
||||
// Single teacher
|
||||
results.push(makeResult(teacherListStr, spec, teacherMap));
|
||||
}
|
||||
|
||||
@@ -80,8 +87,9 @@ export default function parseAbsence(input, teacherMap = {}) {
|
||||
const markConsumed = (start, end) => consumed.push([start, end]);
|
||||
const isConsumed = (i) => consumed.some(([a, b]) => i >= a && i < b);
|
||||
|
||||
// Regex: teacher-list [+ optional spec]
|
||||
const teacherListThenSpecRe = /([A-Za-z]+(?:[,;]\s?[A-Za-z]+)*)(?:\s*)?(\d+(?:\+|-\d+)?)/g;
|
||||
const teacherListThenSpecRe =
|
||||
/([A-Za-z]+(?:[,;]\s?[A-Za-z]+)*)(?:\s*)(\d+(?:\+|-\d+|,\d+)?)(?![A-Za-z])/g;
|
||||
|
||||
let m;
|
||||
while ((m = teacherListThenSpecRe.exec(s)) !== null) {
|
||||
const matchStart = m.index;
|
||||
@@ -119,7 +127,7 @@ export default function parseAbsence(input, teacherMap = {}) {
|
||||
}
|
||||
|
||||
// Bare specs without teacher → invalid
|
||||
const specOnlyRe = /\b(\d+(?:\+|-\d+)?)\b/g;
|
||||
const specOnlyRe = /\b(\d+(?:\+|-\d+|,\d+)?)\b/g;
|
||||
while ((m = specOnlyRe.exec(s)) !== null) {
|
||||
const matchStart = m.index;
|
||||
if (isConsumed(matchStart)) continue;
|
||||
|
||||
Reference in New Issue
Block a user