[Fixed] Disable mat-datepicker with holidays list and weekdays(saturday & Sunday) in angular material

Issue

I am trying to disable the dates based on list of holidays (Getting from api), and also I want to disable weekdays i.e Saturday and Sunday. I am able to disable list of holidays date, but can’t able to disable the weekdays. Here is my code that I have used.

<input matInput [matDatepickerFilter]="holidayDateFilter" [matDatepicker]="picker">

holidayDateFilter = (d: Date): boolean => {
let d = moment(d);
if (this.holidayList) {
  return !this.holidayList.find((x) => {
    return moment(x).isSame(d, 'day');
  })
}

}

Now, where to I put condition for disabling weekends.

Please help me with this.
Thanks in advance.

Solution

You can add functionality to check if the day is weekend.

holidayDateFilter = (d: Date): boolean => {
  // check if date is weekend day
  if (date.getDay() === 0 || date.getDay() === 6) {
    return true;
  }

  // check if date is holiday
  let d = moment(d);
  if (this.holidayList) {
    return !this.holidayList.find(x => {
      return moment(x).isSame(d, 'day');
    });
  }
};

Leave a Reply

(*) Required, Your email will not be published