SOURCE

class Calendar{
    static map={
        1:31,
        2:29,
        3:31,
        4:30,
        5:31,
        6:30,
        7:31,
        8:31,
        9:30,
        10:31,
        11:30,
        12:31,
    }

    constructor(now){
        if(!now){
            now=new Date();
        }
        this.init(now);
    }

    init(now){
        this.now=now;
        const [date,month,year]=[this.date,this.month,this.year]=[ now.getDate(),now.getMonth()+1,now.getYear()+1900];
        this.yearFlag();
    }
    
    yearFlag(){
        // console.log(Number(String(this.year).substr(-2))/4,'number')
        if(Number(String(this.year).substr(-2))%4===0){
            Calendar.map[2]=29;
        }else{
            Calendar.map[2]=28;
        }
    }

    get(){
        return Array(Calendar.map[this.month]).
        fill(null).
        map((o,i)=>({current:this.date===i+1,date:i+1,label:`${this.month}月${i+1}日`,year:this.year}))
    }

    firstYear(){
        this.year-=1;
        this.yearFlag();
        return this.get();
    }
    
    nextYear(){
        this.year+=1;
        this.yearFlag();
        return this.get();
    }

    firstMonth(){
        this.month-=1;
         if(this.month<1){
            this.firstYear();
            this.month=12;
        }
        return this.get();
    }

    nextMonth(){
        this.month+=1;
        if(this.month>12){
            this.nextYear();
            this.month=1;
        }
        return this.get();
    }

    firstDate(){
        this.date-=1;
        if(this.date<1){
            this.firstMonth();
            this.date=this.get().length()-1;
        }
        return this.get();
    }
    
    nextDate(){
        this.date+=1;
        if(this.date>31){
            this.nextMonth();
            this.date=1;
        }
        return this.get();
    }

}

const calendar=new Calendar(new Date("2021-02-10"));

console.log(calendar.get())
console 命令行工具 X clear

                    
>
console