fix: Another another fucking teacher absence
All checks were successful
Remote Deploy / deploy (push) Successful in 1m20s
All checks were successful
Remote Deploy / deploy (push) Successful in 1m20s
Co-authored-by: Jakub Žitník <email@jzitnik.dev>
This commit is contained in:
@@ -40,6 +40,9 @@ export interface AbsenceResult {
|
|||||||
|
|
||||||
export const parseSpec = (spec: string | null): Spec | null => {
|
export const parseSpec = (spec: string | null): Spec | null => {
|
||||||
if (!spec) return null;
|
if (!spec) return null;
|
||||||
|
|
||||||
|
spec = spec.replace(/\s+/g, "");
|
||||||
|
|
||||||
let m;
|
let m;
|
||||||
|
|
||||||
// Handle "6,7"
|
// Handle "6,7"
|
||||||
@@ -118,7 +121,7 @@ export default function parseAbsence(input: string, teacherMap: TeacherMap = {})
|
|||||||
|
|
||||||
// 1. Teachers with specific hours (e.g. "Ab 1-4")
|
// 1. Teachers with specific hours (e.g. "Ab 1-4")
|
||||||
const teacherListThenSpecRe =
|
const teacherListThenSpecRe =
|
||||||
/([A-Za-z]+(?:[,;]\s?[A-Za-z]+)*)(?:\s*)(\d+(?:\+|-\d+|,\d+)?)(?:\.\s*h)?(?![A-Za-z])/g;
|
/([A-Za-z]+(?:[,;]\s?[A-Za-z]+)*)(?:\s*)(\d+(?:\s*\+|\s*-\s*\d+|\s*,\s*\d+)?)(?:\.\s*h)?(?![A-Za-z])/g;
|
||||||
|
|
||||||
let m;
|
let m;
|
||||||
while ((m = teacherListThenSpecRe.exec(s)) !== null) {
|
while ((m = teacherListThenSpecRe.exec(s)) !== null) {
|
||||||
@@ -157,7 +160,7 @@ export default function parseAbsence(input: string, teacherMap: TeacherMap = {})
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 1b. Teachers with "-exk" followed by spec (e.g. "Ex-exk. 3+")
|
// 1b. Teachers with "-exk" followed by spec (e.g. "Ex-exk. 3+")
|
||||||
const teacherExkWithSpecRe = /([A-Za-z]+)-exk(?:\.)?\s*(\d+(?:\+|-\d+|,\d+)?)/gi;
|
const teacherExkWithSpecRe = /([A-Za-z]+)-exk(?:\.)?\s*(\d+(?:\s*\+|\s*-\s*\d+|\s*,\s*\d+)?)/gi;
|
||||||
while ((m = teacherExkWithSpecRe.exec(s)) !== null) {
|
while ((m = teacherExkWithSpecRe.exec(s)) !== null) {
|
||||||
const matchStart = m.index;
|
const matchStart = m.index;
|
||||||
const matchEnd = teacherExkWithSpecRe.lastIndex;
|
const matchEnd = teacherExkWithSpecRe.lastIndex;
|
||||||
@@ -251,7 +254,7 @@ export default function parseAbsence(input: string, teacherMap: TeacherMap = {})
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 5. Bare specs without teacher → invalid
|
// 5. Bare specs without teacher → invalid
|
||||||
const specOnlyRe = /\b(\d+(?:\+|-\d+|,\d+)?)\b/g;
|
const specOnlyRe = /\b(\d+(?:\s*\+|\s*-\s*\d+|\s*,\s*\d+)?)\b/g;
|
||||||
while ((m = specOnlyRe.exec(s)) !== null) {
|
while ((m = specOnlyRe.exec(s)) !== null) {
|
||||||
const matchStart = m.index;
|
const matchStart = m.index;
|
||||||
if (isConsumed(matchStart)) continue;
|
if (isConsumed(matchStart)) continue;
|
||||||
|
|||||||
@@ -286,6 +286,15 @@ test("Ex-exk. 3", [
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
test("Su 4 - 6", [
|
||||||
|
{
|
||||||
|
teacher: "MUDr. Kristina Studénková",
|
||||||
|
teacherCode: "su",
|
||||||
|
type: "range",
|
||||||
|
hours: {from: 4, to: 6},
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
function test(input: string, expectedOutput: any[]) {
|
function test(input: string, expectedOutput: any[]) {
|
||||||
const res = parseAbsence(input, teachermap);
|
const res = parseAbsence(input, teachermap);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user