From 0acf4e0774e0daeed2c386e4d9c0ac36da70a244 Mon Sep 17 00:00:00 2001 From: Noah Loomans Date: Mon, 5 Sep 2016 19:55:53 +0200 Subject: you can now search by name --- lib/getURLOfUsers.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 lib/getURLOfUsers.js (limited to 'lib') diff --git a/lib/getURLOfUsers.js b/lib/getURLOfUsers.js new file mode 100644 index 0000000..8590ee4 --- /dev/null +++ b/lib/getURLOfUsers.js @@ -0,0 +1,45 @@ +const leftPad = require('left-pad') + +// copied from http://www.meetingpointmco.nl/Roosters-AL/doc/dagroosters/untisscripts.js, +// were using the same code as they do to be sure that we always get the same +// week number. +function getWeek () { + // Create a copy of this date object + var target = new Date() + + // ISO week date weeks start on monday + // so correct the day number + var dayNr = (target.getDay() + 6) % 7 + + // ISO 8601 states that week 1 is the week + // with the first thursday of that year. + // Set the target date to the thursday in the target week + target.setDate(target.getDate() - dayNr + 3) + + // Store the millisecond value of the target date + var firstThursday = target.valueOf() + + // Set the target to the first thursday of the year + // First set the target to january first + target.setMonth(0, 1) + // Not a thursday? Correct the date to the next thursday + if (target.getDay() !== 4) { + target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7) + } + + // The weeknumber is the number of weeks between the + // first thursday of the year and the thursday in the target week + return 1 + Math.ceil((firstThursday - target) / 604800000) // 604800000 = 7 * 24 * 3600 * 1000 +} + +function getURLOfUsers (weekOffset, type, id) { + return `http://www.meetingpointmco.nl/Roosters-AL/doc/dagroosters/` + + `${getWeek() + weekOffset}/${type}/${type}${leftPad(id, 5, '0')}.htm` +} + +module.exports = getURLOfUsers + +module.exports.CLASS = 'c' +module.exports.TEACHERS = 't' +module.exports.ROOMS = 'r' +module.exports.STUDENTS = 's' -- cgit v1.1