<?php
/**
* This function gets a year as a parameter and returns an integer,
* which is 29 for leap years and 28 for normal years.
*
* @param int $year
* @return int
*/
function isLeapYear($year)
{
# Check for valid parameters #
if (!is_int($year) || $year < 0)
{
printf('Wrong parameter for $year in function isLeapYear. It must be a positive integer.');
exit();
}
# In the Gregorian calendar there is a leap year every year divisible by four
# except for years which are both divisible by 100 and not divisible by 400.
if ($year % 4 != 0)
{
return 28;
}
else
{
if ($year % 100 != 0)
{
return 29; # Leap year
}
else
{
if ($year % 400 != 0)
{
return 28;
}
else
{
return 29; # Leap year
}
}
}
}
?>