forked from ScoDoc/ScoDoc
Update opolka/ScoDoc from ScoDoc/ScoDoc #2
@ -573,20 +573,43 @@ function formatDate(date, styles = { dateStyle: "full" }) {
|
||||
function updateDate() {
|
||||
const dateInput = document.querySelector("#tl_date");
|
||||
|
||||
const date = dateInput.valueAsDate;
|
||||
const date = dateInput.valueAsDate ?? new Date();
|
||||
let dateStr = "";
|
||||
|
||||
if (!verifyNonWorkDays(date.getDay(), nonWorkDays)) {
|
||||
$("#datestr").text(formatDate(date).capitalize());
|
||||
dateInput.setAttribute("value", date.toISOString().split("T")[0]);
|
||||
return true;
|
||||
dateStr = formatDate(date).capitalize();
|
||||
} else {
|
||||
// On se rend au dernier jour travaillé disponible
|
||||
const lastWorkDay = getNearestWorkDay(date);
|
||||
const att = document.createTextNode(
|
||||
`Le jour sélectionné (${formatDate(date)}) n'est pas un jour travaillé.`
|
||||
);
|
||||
openAlertModal("Erreur", att, "", "crimson");
|
||||
dateInput.value = dateInput.getAttribute("value");
|
||||
return false;
|
||||
const div = document.createElement("div");
|
||||
div.appendChild(att);
|
||||
div.appendChild(document.createElement("br"));
|
||||
div.appendChild(
|
||||
document.createTextNode(
|
||||
`Le dernier jour travaillé disponible a été sélectionné : ${formatDate(
|
||||
lastWorkDay
|
||||
)}.`
|
||||
)
|
||||
);
|
||||
openAlertModal("Attention", div, "", "#eec660");
|
||||
dateInput.value = lastWorkDay.toISOString().split("T")[0];
|
||||
dateStr = formatDate(lastWorkDay).capitalize();
|
||||
}
|
||||
document.querySelector("#datestr").textContent = dateStr;
|
||||
return true;
|
||||
}
|
||||
|
||||
function getNearestWorkDay(date) {
|
||||
const aDay = 86400000; // 24 * 3600 * 1000 | H * s * ms
|
||||
let day = date;
|
||||
let count = 0;
|
||||
while (verifyNonWorkDays(day.getDay(), nonWorkDays) && count++ < 7) {
|
||||
day = new Date(day - aDay);
|
||||
}
|
||||
return day;
|
||||
}
|
||||
|
||||
function verifyDateInSemester() {
|
||||
|
@ -126,7 +126,6 @@
|
||||
function setTimeLineTimes(a, b) {
|
||||
setPeriodValues(a, b);
|
||||
updateJustifyBtn();
|
||||
|
||||
}
|
||||
|
||||
window.forceModule = "{{ forcer_module }}"
|
||||
|
Loading…
Reference in New Issue
Block a user