Показать сообщение отдельно
  #7 (permalink)  
Старый 27.07.2023, 13:46
Uhu Uhu вне форума
Новичок на форуме
Отправить личное сообщение для Uhu Посмотреть профиль Найти все сообщения от Uhu
 
Регистрация: 26.07.2023
Сообщений: 6

переиграли все на яве, но что то неработаю праздники....
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());
Ответить с цитированием