Re: Dates problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Petar Nedyalkov escribió:

On Wednesday 27 April 2005 09:17, Mario de Frutos Dieguez wrote:


Hi!

I have a problem with dates. I have a function that sum a duration in
laboral days to an initial date. The problem come when the function
reaches the last sunday of October, the data remains in the last sunday
of October and make an infinite loop. The functions works fine i have
test in all the cases and only fails in the last sunday of October.



So, let's see the function.



Can anyone help me?

Thanks in advance.

PD: Jochem home english is bad english :P

--
Mario de Frutos Dieguez

División de Ingeniería del Software
y Comunicaciones

CARTIF -Parque Tecnológico Boecillo





function aCalculaFechas($oSqlBDGestion,$fecFechaIniProyecto,$iDuracion)
{
$iCont=0;
//Descomponemos los argumentos y pasamos las fechas a formato Y/m/d
$aFecIniTemp=split("/",$fecFechaIniProyecto);
$fecFechaInicio=date("Y/m/d",mktime(0,0,0,$aFecIniTemp[1],$aFecIniTemp[0],$aFecIniTemp[2]));
if ($iDuracion>0)
{
//Generamos una fecha temporal sobre la que haremos los cálculos
$fecFechaFinTemp=$fecFechaInicio;
//Sumamos uno a la fecha para iniciar la cuenta de la duración un día despues de la fecha de inicio
$fecFechaFinTemp=$this->SumarFechas($fecFechaFinTemp,1);
//Ejecutamos un bucle que irá calculando la duración total (incluyendo sabados y domingos) a partir de la duración
//laboral
while ($iCont<($iDuracion))
{ //Obtenemos el día de la semana del día que estamos mirando $aFecTempCalculo=split('/',$fecFechaFinTemp);
$iDiaSemanaTemp=date("w",mktime(0,0,0,$aFecTempCalculo[1],$aFecTempCalculo[2],$aFecTempCalculo[0]));
//Si el día es distinto de domingo o sabado aumentamos el contador de duración laboral
if ($iDiaSemanaTemp!=6 && $iDiaSemanaTemp!=0)
{
$iCont++;
}
//Se añade uno más a la fecha
$fecFechaFinTemp=$this->SumarFechas($fecFechaFinTemp,1);
//Siempre se añade uno al número de días totales.
$iNumDiasTotales++;
//echo $iNumDiasTotales.'<br>';
}
//Sumamos al a fecha temporal el número de dias totales (solo incluidos sabados y domingos)
$fecFechaFinTemp=$this->SumarFechas($fecFechaInicio,$iNumDiasTotales);
//Hacemos un bucle obteniendo los días festivos usando la fecha final temporal y hasta que no se obtengan dias
//festivos sigue sumandolos.
do
{
//echo "SELECT * FROM festivos WHERE dia_festivo BETWEEN '".$fecFechaInicio."' AND '".$fecFechaFinTemp."'";
//Obtenemos los dias festivos entre el rango de fechas
$iObtenDiasFest=$oSqlBDGestion->iEjecutarConsulta("SELECT * FROM festivos WHERE dia_festivo BETWEEN '".$fecFechaInicio."' AND '".$fecFechaFinTemp."'");
$iNumDiasFestivos=$oSqlBDGestion->iNumeroFilasResultadoConsulta($iObtenDiasFest);
$fecFechaInicio=$this->SumarFechas($fecFechaFinTemp,1);
$fecFechaFinTemp=$this->SumarFechas($fecFechaFinTemp,$iNumDiasFestivos);
}while ($iNumDiasFestivos>0);
$aFecTempCalculo=split('/',$fecFechaFinTemp);
$iDiaSemanaTemp=date("w",mktime(0,0,0,$aFecTempCalculo[1],$aFecTempCalculo[2],$aFecTempCalculo[0]));
if ($iDiaSemanaTemp==6)
$fecFechaFin=$this->SumarFechas($fecFechaFinTemp,3);
else if ($iDiaSemanaTemp==0)
$fecFechaFin=$this->SumarFechas($fecFechaFinTemp,2);
else
$fecFechaFin=$fecFechaFinTemp;
$aFecFin=split("/",$fecFechaFin);
$fecFechaFin=date("d/m/Y",mktime(0,0,0,$aFecFin[1],$aFecFin[2],$aFecFin[0]));
}
else
$fecFechaFin=$fecFechaIniProyecto;


return $fecFechaFin;
}


--
Mario de Frutos Dieguez

División de Ingeniería del Software
y Comunicaciones


CARTIF -Parque Tecnológico Boecillo

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux