Estou usando um script que encontrei nesta pergunta do SOen, e para contar os dias úteis desconsiderando sábado e domingo (dá pra fazer só com domingo tbm, alterando $what_day > 5
para $what_day > 6
por exemplo) ele funciona certinho, mas eu queria incluir o calendário oficial de feriados do Brasil.
Este é o script que está funcionando (já pegando os dados do meu formulário):
<?php
//get current month for example
$beginday = ($_POST ["Tdesl"]);
$lastday = ($_POST ["Tinsem3"]);
$nr_work_days = getWorkingDays($beginday, $lastday);
echo $nr_work_days;
function getWorkingDays($startDate, $endDate)
{
$begin = strtotime($startDate);
$end = strtotime($endDate);
if ($begin > $end) {
echo "startdate is in the future! <br />";
return 0;
} else {
$no_days = 0;
$weekends = 0;
while ($begin <= $end) {
$no_days++; // no of days in the given interval
$what_day = date("N", $begin);
if ($what_day > 5) { // 6 and 7 are weekend days
$weekends++;
};
$begin += 86400; // +1 day
};
$working_days = $no_days - $weekends;
return $working_days;
}
}
O HTML:
<form method="post" id="Cform" name="Tform" action="diasuteis2.php">
<label for="Cinsem">Data inicial:</label>
<input type="date" name="Tinsem3" id="Cinsem" size="6">
<label for="Cdesl22">Data final:</label>
<input type="date" name="Tdesl" id="Cdesl22" size="6"><br><br>
<p align="center">
<input type="submit" id="enviar"></p>
</form>
Um exemplo de saída correta para:
echo $beginday;
echo "<br><br>";
echo $lastday;
echo "<br><br>";
echo $nr_work_days;
É:
2014-12-10
2014-12-15
4
(Ele considerou o dia 10, e excluiu os dias 13 e 14 corretamente)
É possível, ou viável, incluir os feriados neste código? Se alguém puder fazer um exemplo (claro que não precisa incluir todos os feriados, apenas mostrar como posso fazer isso) agradeço desde já.