diff --git a/scripts.js b/scripts.js index 6b275cf..a214553 100644 --- a/scripts.js +++ b/scripts.js @@ -83,6 +83,29 @@ let courseLinks = { 'TINF20B5': {user: 'strand', file: 'TINF20B5'} } +/** + * Calculates, in which semester the given course currently is + * @param course The course to calculate the semester for + * @returns {number} The number of the semester they are in + */ +function calculateSemester(course) { + let yearRegex = new RegExp('[a-zA-Z]*([0-9]{2})B[0-9]'); + + let match = yearRegex.exec(course); + let startYear = '20'; + if (match !== null) { + startYear += match[1]; + } + + let currentYear = new Date().getFullYear(); + + let yearDifference = currentYear - startYear; + + let semesters = yearDifference * 2 + 1; + + return semesters; +} + /* Toggle Dark-Mode */ const toggleDarkMode = () => {