diff --git a/src/routes/uonetplus-opiekun.js b/src/routes/uonetplus-opiekun.js index 719fca7..128898c 100644 --- a/src/routes/uonetplus-opiekun.js +++ b/src/routes/uonetplus-opiekun.js @@ -48,7 +48,7 @@ router.get("/Default/123456/Lekcja(\.mvc|)/PlanLekcji", (req, res) => { res.render("opiekun/plan-lekcji", { title: "Witryna ucznia i rodzica – Paln Lekcji", data: require("../../data/opiekun/plan-lekcji.json"), - time: converter(req.query.data) + weekDays: converter.getWeekDaysFrom(req.query.data) }) }); diff --git a/src/utils/converter.js b/src/utils/converter.js index ddde70e..53adbfa 100644 --- a/src/utils/converter.js +++ b/src/utils/converter.js @@ -1,11 +1,9 @@ -function getDateString(tick) { - let date; +function getDateFromTick(tick) { if (tick === '' || tick === undefined) { - date = getMonday(new Date()); - } else { - date = new Date((tick - 621355968000000000) / 10000); + return getMonday(new Date()); } - return formatDate(date); + + return new Date((tick - 621355968000000000) / 10000); } function formatDate(date) { @@ -17,5 +15,25 @@ function getMonday(date) { return new Date(date.getFullYear(), date.getMonth(), day); } +function getDayName(dateStr) +{ + return new Date(dateStr).toLocaleDateString("pl", { weekday: "long" }); +} -module.exports = getDateString; \ No newline at end of file +function getWeekDaysFrom(tick) { + let startDate = getDateFromTick(tick); + + const days = []; + for(let i = 0; i < 5; i++) { + let date = new Date(startDate).setDate(startDate.getDate() + i); + days.push([ + getDayName(date), + formatDate(new Date(date)) + ]); + } + + return days; +} + +exports.getDateString = getDateFromTick; +exports.getWeekDaysFrom = getWeekDaysFrom; diff --git a/src/views/opiekun/plan-lekcji.pug b/src/views/opiekun/plan-lekcji.pug index 26d20c1..71a48e1 100644 --- a/src/views/opiekun/plan-lekcji.pug +++ b/src/views/opiekun/plan-lekcji.pug @@ -1,7 +1,6 @@ extends layout append content - - var times = time; main.mainContainer h1 Plan lekcji div @@ -10,26 +9,11 @@ append content tr th Lekcja th Pora lekcji - th - | poniedziałek - br - | #{times} - th - | wtorek - br - | 20.06.2017 - th - | środa - br - | 21.06.2017 - th - | czwartek - br - | 22.06.2017 - th - | piątek - br - | 23.06.2017 + each item in weekDays + th + | #{item[0]} + br + | #{item[1]} tbody each item in data tr