переиграли все на яве, но что то неработаю праздники....
function getShippingDate() {
var today = new Date();
var day = today.getDay();
var hour = today.getHours();
var minute = today.getMinutes();
var holidays = ["28.07.2023", "31.07.2023"];
var shippingDate;
var shippingTime;
if (day >= 1 && day <= 5) {
if (hour >= 0 && hour <= 9 && minute >= 1 && minute <= 59) {
if (!isHoliday(getNextDay())) {
shippingDate = "heute";
shippingTime = "ab 12 Uhr";
} else {
shippingDate = getNextWorkDay();
}
} else if (hour >= 10 && hour <= 15 && minute >= 0 && minute <= 59) {
if (!isHoliday(today)) {
shippingDate = "heute";
var currentHour = hour + 2;
var roundedHour = Math.ceil(currentHour / 0.5) * 0.5;
shippingTime = "ab " + roundedHour + " Uhr";
} else {
shippingDate = getNextWorkDay();
shippingTime = "ab 12 Uhr";
}
} else if (hour >= 16 && hour <= 23 && minute >= 1 && minute <= 59) {
if (!isHoliday(getNextDay())) {
shippingDate = "morgen";
shippingTime = "ab 12 Uhr";
} else {
shippingDate = getNextWorkDay();
shippingTime = "ab 12 Uhr";
}
}
} else if (day === 5 && hour >= 16 && hour <= 23 && minute >= 1 && minute <= 59) {
shippingDate = getNextWorkDay();
shippingTime = "ab 12 Uhr";
} else if (day === 6 || day === 0) {
shippingDate = getNextWorkDay();
shippingTime = "ab 12 Uhr";
}
return "Angestrebter Versand- / Abholtermin: " + shippingDate + " " + shippingTime;
}
function isHoliday(date) {
var dateString = date.toLocaleDateString();
return holidays.includes(dateString);
}
function getNextDay() {
var today = new Date();
var nextDay = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1);
return nextDay;
}
function getNextWorkDay() {
var nextDay = getNextDay();
while (isHoliday(nextDay) || nextDay.getDay() === 6 || nextDay.getDay() === 0) {
nextDay.setDate(nextDay.getDate() + 1);
}
return nextDay.toLocaleDateString();
}
console.log(getShippingDate());