From 4f0ec02153703d7ae845efb3830a5d065b393dd2 Mon Sep 17 00:00:00 2001 From: rstular Date: Sat, 16 May 2020 19:13:09 +0200 Subject: Bug fix - handling afternoon lessons --- js/gsec.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/js/gsec.js b/js/gsec.js index 79bda35..780d542 100644 --- a/js/gsec.js +++ b/js/gsec.js @@ -362,10 +362,13 @@ class gsec { } fetchAbsences(fromDate = null, tillDate = null) { // navedba datumov je deprecated. Internet je dovolj hiter za poslat maksimalno 4160 ur (16 ur/dan, 5 dni/ted, 52 ted/leto) + + const FIELDS_REGEX = /^(.+) \((\dP?)<\/span>/; + return new Promise((resolve, reject)=>{ if (!(fromDate instanceof Date) || !(tillDate instanceof Date)) { tillDate = new Date(Date.UTC(9999, 11, 30)); // overkill? Of course not, cez 8000 let bo ta app se vedno top shit - fromDate = new Date(Date.UTC(1, 1, 1)); // i don't thunk so + fromDate = new Date(Date.UTC(1, 1, 1)); // i don't think so } var dataToBeSent = { @@ -390,10 +393,14 @@ class gsec { var subjects = {}; for (const subject of subFields[2].innerHTML.split(", ")) { - var subjectName = subject.split(" (")[0]; - var status = Number(subject.split('(')[0]); - // statusi so: 0: ni obdelano, 1: opravičeno, 2: neopravičeno, 3: ne šteje, uporabi S(gseAbsenceTypes[num]) za i18n pre3vod - var period = Number(subject.split('">').pop().split('')[0]); + const matched_info = FIELDS_REGEX.exec(subject); + + var subjectName = matched_info[1]; + var status = Number(matched_info[2]); + // statusi so: 0: ni obdelano, 1: opravičeno, 2: neopravičeno, 3: ne šteje, uporabi S(gseAbsenceTypes[num]) za i18n prevod + // Ce je v "stevilki" P, gre za popoldansko uro -> +7 ur + var period = matched_info[3]; + period = period.includes("P") ? Number(period.replace("P", "")) + 7 : Number(period); subjects[period] = {status: status, subject: subjectName}; } absences.push({subjects: subjects, date: dateObj}); -- cgit v1.2.3