Jours ouvrés en php

Bonjour,

je suis en php et je cherche à coder une fonction qui stocke dans un tableau les dates des jours ouvrés, j'ai codé une fonction mais lors de l'execution y a une ligne qui prend plus de trente secondes je comprends pas pourquoi

Si vous pouvez m'aider svp sa sera génial
Merci

voila mon code

<?php

$date_debutCP = '11/07/2008' ;
$date_finCP = '17/07/2008' ;

function NbJours($date_debutCP, $date_finCP)
{
$tDeb = explode("/", $date_debutCP);
$tFin = explode("/", $date_finCP);

$diff = mktime(0, 0, 0, $tFin[1], $tFin[0], $tFin[2]) -
mktime(0, 0, 0, $tDeb[1], $tDeb[0], $tDeb[2]);

return(($diff / 86400)+1);

}

$tDeb = explode("/", $date_debutCP);
$tFin = explode("/", $date_finCP);

$timestampEnd = mktime(0, 0, 0, $tFin[1], $tFin[0], $tFin[2]);
$timestampStart = mktime(0, 0, 0, $tDeb[1], $tDeb[0], $tDeb[2]);

function jour_ferie($timestampStart, $timestampEnd, $nb)
{

$jour = date("d", $timestampStart);
$mois = date("m", $timestampStart);
$an = date("Y", $timestampStart);
$nbFerie = 0;
$nbFerie2 = 0;
$temp = array();
while ($timestampStart <= $timestampEnd)
{

$jour_julien = unixtojd($timestampStart);
$jour_semaine = jddayofweek($jour_julien, 0);
if($jour_semaine != 0 || $jour_semaine != 6)
{
for($j=0;$j<=$nb;$j++){

$timestamp = mktime(0, 0, 0, $mois, $jour+$j, $an);
$temp[$j] = date("Y-m-d", $timestamp);}

}

}

return $temp;

}

$a=NbJours($date_debutCP, $date_finCP);
$tab = array();
$tab=jour_ferie($timestampStart, $timestampEnd, $a);
for($k=0;$k<count($tab);$k++){
echo $tab[$k];
echo "<br/>";
}

?>
Configuration: Windows 2000
Internet Explorer 6.0

4 réponses

  1. Tu pourrais utilise la balise code pour conservé les TAB, j'ai pas envie de lire sa..
    1. Bonjour,

      J'ai reformulé mon code mais je n'arrive tjs pas à virer les samedis et dimanches.

      Pleaze si vous avez des idées à me donner , merci bcp!

      function diff_date($jour , $mois , $an , $jour2 , $mois2 , $an2){
      $timestamp2 = mktime(0, 0, 0, $mois, $jour, $an);
      $timestamp = mktime(0, 0, 0, $mois2, $jour2, $an2);

      $diff = floor(($timestamp - $timestamp2) / (3600 * 24));
      return $diff;
      }

      function jour_ferie($jour, $mois, $an, $jour2, $mois2, $an2, $nb)
      {

      $timestampStart= mktime(0, 0, 0, $mois, $jour, $an);
      $timestampEnd = mktime(0, 0, 0, $mois2, $jour2, $an2);
      $temp = array();
      $j=0;
      while ($timestampStart <= $timestampEnd)
      {

      $jour_julien = unixtojd($timestampStart);
      $jour_semaine = jddayofweek($jour_julien, 0);

      if($jour_semaine != 0 || $jour_semaine != 6)
      {

      $temp[$j] = date("Y-m-d", $timestampStart);
      $j++;

      }

      $jour++;
      $timestampStart=mktime(0,0,0,$mois,$jour,$an);

      }

      return $temp;

      }

      $a=diff_date('11', '07', '2008', '17', '07', '2008');
      $tab = array();
      $tab=jour_ferie('11', '07', '2008', '17', '07', '2008', $a);
      for($k=0;$k<count($tab);$k++){
      echo $tab[$k];
      echo "<br/>";
      }

      ?>
      1. Merci Tiller,

        j'ai incrémenté la variable $timespampStart dans ma boucle et du coup j'ai des dates qui correspondent pas à mes dates j'ai ça

        2016-07-17
        2016-07-18
        2016-07-19
        2016-07-20
        2016-07-21
        2016-07-22
        2016-07-23
        2016-07-24

        alors que j'avais mis

        $date_debutCP = '11/07/2008' ;
        $date_finCP = '17/07/2008' ;

        voila ma fonction

        function jour_ferie($timestampStart, $timestampEnd, $nb)
        {

        $jour = date("d", $timestampStart);
        $mois = date("m", $timestampStart);
        $an = date("Y", $timestampStart);
        $temp = array();
        while ($timestampStart <= $timestampEnd)
        {

        $jour_julien = unixtojd($timestampStart);
        $jour_semaine = jddayofweek($jour_julien, 0);

        if($jour_semaine != 0 || $jour_semaine != 6)
        {

        for($j=0;$j<=$nb;$j++)
        {

        $timestamp = mktime(0, 0, 0, $mois, $jour+$j, $an);
        $temp[$j] = date("Y-m-d", $timestamp);

        }

        }

        $jour++;
        $timestampStart=mktime(0,0,0,$mois,$jour,$annee);

        }

        return $temp;

        }
        1. while ($timestampStart <= $timestampEnd)
          {
              $jour_julien = unixtojd($timestampStart);
              $jour_semaine = jddayofweek($jour_julien, 0);
              if($jour_semaine != 0 || $jour_semaine != 6)
              {
                  for($j=0;$j<=$nb;$j++){
                 
                  $timestamp = mktime(0, 0, 0, $mois, $jour+$j, $an);
                  $temp[$j] = date("Y-m-d", $timestamp);}
              }
          } 


          T'as une boucle infini ici, Tu boucles tant que $timespampStart est inférieur a l'autre, mais jamais tu l'incrémente