Checking if the year is a leap year

You need to check the year (not the current one) for a leap year. Found this algorithm:

  1. The year is divisible by 400 -> leap year -> end
  2. The year is divisible by 100 -> non-leap year -> end
  3. The year is divisible by 4 -> leap year -> end
  4. Non-leap year -> end
  5. All

Is he faithful?
(How can a number be divisible by 400 and not divisible by 100?)


Answer 1, authority 100%

function isLeap($year)
{
    return date("L", mktime(0,0,0, 7,7, $year));
}

If the year is a high year then returns 1 otherwise 0

UPD:

well, or so 🙂 As they say, for lovers of difficult paths 🙂

function isLeap($y){return $y % 400 == 1 || ($y % 100 != 0 && ($y & 3) == 0);}

Answer 2

Isn’t it easier to leave one condition if the remainder of division by 4 is 0, then it’s a leap year, non-zero normal?