Commit 70c5a7fc authored by liziwl's avatar liziwl
Browse files

fix redirect bug

parent b1ff02a4
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -25,39 +25,38 @@
  export default {
    mounted () {
    function bus_redirect(){
        var day_map = {};
        // JSON is from https://github.com/NateScarlet/holiday-cn
        // need to update by year
        $.getJSON("/2021.json", function (data) {
            var day_map = {};
            for (let i = 0; i < data.days.length; i++) {
                item = data.days[i];
                day_map[item.date] = item.isOffDay;
                day_map[data.days[i].date] = data.days[i].isOffDay;
            }
        });
        // console.log(day_map);
            var now_date = new Date();
            var ye = new Intl.DateTimeFormat('en', {year: 'numeric'}).format(now_date);
            var mo = new Intl.DateTimeFormat('en', {month: '2-digit'}).format(now_date);
            var da = new Intl.DateTimeFormat('en', {day: '2-digit'}).format(now_date);
            var day_key = `${ye}-${mo}-${da}`;
        var day_in_week = now_date.getDay();
            var is_holiday;
            if (day_map[day_key] == null) {
                // 不在国家假日调整表里
                console.log("Not in GOV declaration");
                var day_in_week = now_date.getDay();
                var isWeekend = (day_in_week == 6) || (day_in_week == 0);
                // 6 = Saturday, 0 = Sunday
                is_holiday = isWeekend;
            console.log(isWeekend);
            console.log("No in GOV declaration")
            } else {
                console.log("In GOV declaration");
                is_holiday = day_map[day_key];
            console.log(day_map[day_key]);
            console.log("In GOV declaration")
            }
            if (is_holiday){
                console.log("节假日");
                location.href = "/transport/holiday.html";
            }else {
                console.log("工作日");
                location.href = "/transport/workday.html";
            }
        });
    }

    document.addEventListener('DOMContentLoaded', bus_redirect, false);