Make week days var

This commit is contained in:
Mikołaj Pich 2017-12-15 00:49:35 +01:00
parent b48927b761
commit afbaac27ca
3 changed files with 31 additions and 29 deletions

View file

@ -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)
})
});

View file

@ -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;
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;

View file

@ -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