Files
Timetable-V2/src/util.js
2023-08-25 14:42:38 +02:00

55 lines
1.7 KiB
JavaScript

export function getSubstitutionText(substitution, includeClass) {
const includeClassValue = includeClass ? "withClass" : "withoutClass";
// TODO: implement more texts
if (substitution.type == "change") {
if (
substitution.teacher == substitution.change.teacher ||
!substitution.change.teacher
) {
return `substitution.text.${includeClassValue}.subjectChange`;
} else {
return `substitution.text.${includeClassValue}.teacherChange`;
}
} else if (substitution.type == "cancellation") {
return `substitution.text.${includeClassValue}.cancellation`;
}
return "";
}
export function getSubstitutionColor(substitution) {
if (!substitution) return;
switch (substitution.type) {
case "change":
return "background-color: var(--substitution-background-change);";
case "cancellation":
return "background-color: var(--substitution-background-cancellation);";
}
}
export function getDateSkippingWeekend(date, onlyNext) {
// Go from saturday to next monday
if (date.getDay() == 6) return new Date(date.getTime() + 86400000 * 2);
// Go from sunday to last friday or next monday
if (date.getDay() == 0)
return new Date(
onlyNext ? date.getTime() + 86400000 * 1 : date.getTime() - 86400000 * 2,
);
return date;
}
export function getNextAndPrevDay(date) {
return [
new Date(date.getTime()),
getDateSkippingWeekend(new Date(date.getTime() + 86400000)),
getDateSkippingWeekend(new Date(date.getTime() - 86400000)),
].map((e) => e.getTime());
}
export function setUTCMidnight(date) {
// Set the time to UTC midnight while keeping the correct date
return new Date(
Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()),
);
}