Commit 5612881b authored by liziwl's avatar liziwl
Browse files

加入自动日期选择

parent a2827b8d
Loading
Loading
Loading
Loading
+42 −1
Original line number Diff line number Diff line
@@ -12,6 +12,47 @@

## 时间表 Timetable

<script>
import axios from "axios";
export default {
    mounted() {
        axios
            .get("/2021.json")
            .then(response => (bus_redirect(response.data)));
        function bus_redirect(holidata) {
            // JSON is from https://github.com/NateScarlet/holiday-cn
            // need to update by year.
            // Download the JSON to path "docs/.vuepress/public/YYYY.json"
            var day_map = {};
            for (let i = 0; i < holidata.days.length; i++) {
                day_map[holidata.days[i].date] = holidata.days[i].isOffDay;
            }
            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 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;
            } else {
                console.log("In GOV declaration");
                is_holiday = day_map[day_key];
            }
            if (is_holiday) {
                console.log("节假日");
            } else {
                console.log("工作日");
            }
        }
    },
}
</script>

<object-selector :objs="{
    '工作日 Workday': true,