Uhu,
<!DOCTYPE html>
<html>
<head>
<title>Versandtermin</title>
<meta charset="utf-8">
<script>
function getShippingDate() {
let today = new Date();
let hour = today.getHours();
let shippingDate = document.getElementById("shipping-date");
let shippingTime = document.getElementById("shipping-time");
let nextDay = getNextFreeDay(today);
let Tag = `morgen ${nameWeekday(nextDay)} ${dateFormat(nextDay)}`;
let Uhrzeit = "ab 12 Uhr";
if (!isDayHoliday(today)) {
if (hour < 10) {
Tag = "heute"
} else if (hour < 16) {
Tag = "heute";
Uhrzeit = `ab ${hour+2} Uhr`
}
}
shippingDate.innerHTML = Tag;
shippingTime.innerHTML = Uhrzeit;
function dateFormat(date) {
let formatter = new Intl.DateTimeFormat("ru", {
day: "2-digit",
month: "2-digit",
year: "numeric"
});
return formatter.format(date)
}
function nameWeekday(date) {
let formatter = new Intl.DateTimeFormat("de", {
weekday: "long"
});
return formatter.format(date)
}
function isDayHoliday(date) {
let holidays = ["26.07.2023", "28.07.2023", "01.08.2023", "05.08.2023"];
return holidays.includes(dateFormat(date)) || date.getDay() === 6 || date.getDay() === 0 || (date.getDay() === 5 && date.getHours() >= 16)
}
function getNextFreeDay(date) {
do {
date.setDate(date.getDate() + 1);
} while (isDayHoliday(date))
return date;
}
}
document.addEventListener('DOMContentLoaded', getShippingDate)
</script>
</head>
<body>
<h1>Versandtermin</h1>
<p>Angestrebter Versand- / Abholtermin: <span id="shipping-date"></span> <span id="shipping-time"></span></p>
</body>
</html>