JS Leap year issue

I have the following, but not sure why it isn’t picking up this year as a leap year. Any idea?

CalendarMonth.prototype.correctForLeapYear = function()
{
	if(this.year%4 != 0)
	{
		daysInMonth[1] = 28;
		this.isLeapYear = 0;
	 }
	else if(this.year%400 == 0)
	{
		daysInMonth[1] = 29;
		this.isLeapYear = 1;
	}
	else if(this.year%100 == 0)
	{
		daysInMonth[1] = 28;
		this.isLeapYear = 0;
	 }
	else
	{
		daysInMonth[1] = 29;
		this.isLeapYear = 1;
	}
}

Thanks
Martin

When it’s not a leap year and you set a date to the 29th of February, it will roll over to the first of March.


this.isLeapYear = (new Date(this.year, 1, 29).getDate() === 29);

That’s the best way for you to determine if the year is a leap year.