禁用除母亲节以外的所有星期天

Disable all sundays except mother day

我想在 flatpickr 中禁用所有星期天,这工作正常。但现在我想定义一些例外情况,例如母亲节。这是我的代码,但是 if 块将始终执行,我仍然不能 select 母亲节。

   // Mothers Day -> dd.mm.yyyy
   const d = new Date();
   d.setMonth(4); // May
   d.setDate(8); // May 8 is the earliest possible date
   // while not a sunday, move to next day
   while (d.getUTCDay()) d.setDate(d.getDate() + 1);
   const motherDayDate = new Intl.DateTimeFormat('de-DE', { day: "2-digit", month: "2-digit", year: "numeric"}).format(d);

  $(".datePicker").flatpickr({
    enableTime: false,
    dateFormat: "d.m.Y",
    minDate: "today",
    "locale": {
        "firstDayOfWeek": 1
    },
    "disable": [
        function(date) {
            //  motherDayDate = e.g. 09.05.2021
            if (moment(date).format("DD.MM.YYYY") === motherDayDate){
                alert ("mother");
                return true;
            }
            
            // 0 = Sunday
            return (date.getDay() === 0);
        }
    ]
});

我对 flatpickr 不是很熟悉,但也许你应该在代码 alert("mother");?

下面返回 false

(如果我有足够的声誉,我会把它作为评论发布。不过希望这有帮助!)