THis is my HTML

 <div class="row">
              <div class="col-4">
                <p-calendar label="startDate" formControlName="startDate"
                  [minDate]="daMaxRange"
                  [maxDate]="formGroup.controls['endDate'].value ? formGroup.controls['endDate'].value : maxDate"
                  (onBlur)="calculateMaxDataA(formGroup.controls['startDate'].value)"
                  (onChange)="calculateMaxDataA(formGroup.controls['startDate'].value)">
                </p-calendar>
              </div>
              <div class="col-4">
                <p-calendar label="EndDate" formControlName="dataPrescrizioneA"
                  [minDate]="formGroup.controls['startDate'].value" [maxDate]="aMaxRange"
                  (onBlur)="calculateMinDataDa(formGroup.controls['endDate'].value)"
                  (onChange)="calculateMinDataDa(formGroup.controls['endDate'].value)"></p-calendar>
              </div>
            </div>
    

THose are methods. I need to a range from january 31 to dicember 1st 2023, for example and have to alculate if the ywar is a leap year.

calculateMinDataDa(){
}
calculateMinDataA(){
}
1

There are 1 best solutions below

0
Eliseo On

The easy way in javascript to know if a year is a leap year is

isLeap(year:number)
{
    const date=new Date(year,1,29);  //29 of febrary of the year you want
    return date.getMonth()==1;  //if the month is 1 (febrary) is leap year
}

console.log(this.isLeap(2023)) //false
console.log(this.isLeap(2024)) //true