parent
f4d6cd635f
commit
3ad9ab15d5
@ -573,20 +573,43 @@ function formatDate(date, styles = { dateStyle: "full" }) {
|
|||||||
function updateDate() {
|
function updateDate() {
|
||||||
const dateInput = document.querySelector("#tl_date");
|
const dateInput = document.querySelector("#tl_date");
|
||||||
|
|
||||||
const date = dateInput.valueAsDate;
|
const date = dateInput.valueAsDate ?? new Date();
|
||||||
|
let dateStr = "";
|
||||||
|
|
||||||
if (!verifyNonWorkDays(date.getDay(), nonWorkDays)) {
|
if (!verifyNonWorkDays(date.getDay(), nonWorkDays)) {
|
||||||
$("#datestr").text(formatDate(date).capitalize());
|
dateStr = formatDate(date).capitalize();
|
||||||
dateInput.setAttribute("value", date.toISOString().split("T")[0]);
|
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
|
// On se rend au dernier jour travaillé disponible
|
||||||
|
const lastWorkDay = getNearestWorkDay(date);
|
||||||
const att = document.createTextNode(
|
const att = document.createTextNode(
|
||||||
`Le jour sélectionné (${formatDate(date)}) n'est pas un jour travaillé.`
|
`Le jour sélectionné (${formatDate(date)}) n'est pas un jour travaillé.`
|
||||||
);
|
);
|
||||||
openAlertModal("Erreur", att, "", "crimson");
|
const div = document.createElement("div");
|
||||||
dateInput.value = dateInput.getAttribute("value");
|
div.appendChild(att);
|
||||||
return false;
|
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() {
|
function verifyDateInSemester() {
|
||||||
|
@ -126,7 +126,6 @@
|
|||||||
function setTimeLineTimes(a, b) {
|
function setTimeLineTimes(a, b) {
|
||||||
setPeriodValues(a, b);
|
setPeriodValues(a, b);
|
||||||
updateJustifyBtn();
|
updateJustifyBtn();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window.forceModule = "{{ forcer_module }}"
|
window.forceModule = "{{ forcer_module }}"
|
||||||
|
Loading…
Reference in New Issue
Block a user