[eluser]Crucial[/eluser]
I just started using the calendar class for an accounting/finance type application, and was wondering why the
get_total_days function used so much code for something that's already built into PHP?
Current PHP Code
Code:
function get_total_days($month, $year)
{
$days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
if ($month < 1 OR $month > 12)
{
return 0;
}
// Is the year a leap year?
if ($month == 2)
{
if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0))
{
return 29;
}
}
return $days_in_month[$month - 1];
}
Modified PHP Code
Code:
function get_total_days($month, $year)
{
if ($month < 1 OR $month > 12)
{
return 0;
}
return date('t', mktime(0, 0, 0, $month, 1, $year));
}