OOOk i was experimienting a lot, and this its the result of my fuction
firts we set the monday, i have a function (filter week) that set the value of monday and sunday, for a request that a i send, i post it just for the example.
now in dateclass(), its a function for make the classes of the cells in the date picker change, in the html, on the "<mat-datepicker" use [dateClass]="dateClass()" for calling
now, inside this function i have 2 if, its for validate that the monday its not 30 or 31, in that case the rest of the day are 1,2,3,etc (now im thinking about it i need to fix this validation xD because if tusday are 30 or 31, the problem will persis) anyway, wehn u have the value of avery day of the week, use the function of time .valueOf() to compare de value of time between date (the date value are inside the if inside the if xD) and the value of the day of the week
write me if need help for applicate it. use this referend question for understanding better the way that i set the color of the special days
filterWeek(){
let d = this.selectedW
let day = d.getDay();
let diffm = d.getDate()-day +1;
let diffs = d.getDate()-day +7;
let mon = new Date(d.setDate(diffm));
let sun = new Date(d.setDate(diffs));
if(mon.getDate() > sun.getDate()){
this.monday=mon.getFullYear()+'-'+(mon.getMonth()+1)+'-'+mon.getDate();
this.sunday =sun.getFullYear()+'-'+(sun.getMonth()+2)+'-'+sun.getDate();
}else{
this.monday=mon.getFullYear()+'-'+(mon.getMonth()+1)+'-'+mon.getDate();
this.sunday =sun.getFullYear()+'-'+(sun.getMonth()+1)+'-'+sun.getDate();
}
}
dateClass() {
let l:any =new Date(this.monday);
var day = new Date(new Date(this.monday).getFullYear(), new Date(this.monday).getMonth() + 1, 0);
if(l.getDate() === day.getDate()){
let m:any =new Date(new Date(this.monday).getFullYear(), new Date(this.monday).getMonth() + 1, 1);
let x:any =new Date(new Date(this.monday).getFullYear(), new Date(this.monday).getMonth() + 1, 2);
let j:any =new Date(new Date(this.monday).getFullYear(), new Date(this.monday).getMonth() + 1, 3);
let v:any =new Date(new Date(this.monday).getFullYear(), new Date(this.monday).getMonth() + 1, 4);
let s:any =new Date(new Date(this.monday).getFullYear(), new Date(this.monday).getMonth() + 1, 5);
let d:any =new Date(new Date(this.monday).getFullYear(), new Date(this.monday).getMonth() + 1, 6);
return (date: Date): MatCalendarCellCssClasses => {
if (date.valueOf() === l.valueOf() || date.valueOf() === m.valueOf() || date.valueOf() === x.valueOf()
||date.valueOf() === j.valueOf() || date.valueOf() === v.valueOf() || date.valueOf() === s.valueOf()
|| date.valueOf() === d.valueOf()) {
return 'special-date';
} else {
return;
}
};
}else{
let m:any =new Date(new Date(this.monday).getFullYear(), new Date(this.monday).getMonth() + 1, new Date(this.monday).getDate()+1);
let x:any =new Date(new Date(this.monday).getFullYear(), new Date(this.monday).getMonth() + 2, new Date(this.monday).getDate()+2);
let j:any =new Date(new Date(this.monday).getFullYear(), new Date(this.monday).getMonth() + 2, new Date(this.monday).getDate()+3);
let v:any =new Date(new Date(this.monday).getFullYear(), new Date(this.monday).getMonth() + 2, new Date(this.monday).getDate()+4);
let s:any =new Date(new Date(this.monday).getFullYear(), new Date(this.monday).getMonth() + 2, new Date(this.monday).getDate()+5);
let d:any =new Date(new Date(this.monday).getFullYear(), new Date(this.monday).getMonth() + 2, new Date(this.monday).getDate()+6);
return (date: Date): MatCalendarCellCssClasses => {
if (date.valueOf() === l.valueOf() || date.valueOf() === m.valueOf() || date.valueOf() === x.valueOf()
||date.valueOf() === j.valueOf() || date.valueOf() === v.valueOf() || date.valueOf() === s.valueOf()
|| date.valueOf() === d.valueOf()) {
return 'special-date';
} else {
return;
}
};
}
}