I wrote this maybe one or two years ago... don't have time translating so have fun ! (have an exam ou 30 min !)
<?
$arrNZAU_Jours_Mois = array (
1 => 31,
2 => 28,
3 => 31,
4 => 30,
5 => 31,
6 => 30,
7 => 31,
8 => 31,
9 => 30,
10 => 31,
11 => 30,
12 => 31
);
function NZAU_RETOURNER_MOIS_TOTAL_JOURS($intMois, $intAnnee) {
$intTotal_Jours = $GLOBALS['arrNZAU_Jours_Mois'][$intMois];
$intTotal_Jours += ((($intMois == 2) && !($intAnnee % 4)) ? 1 : 0);
return $intTotal_Jours;
}
function NZAU_RETOURNER_DATE_MODIFIER($strDate, $intDifference, $strMode) {
$intAnnee = intval(substr($strDate, 0, 4));
$intMois = intval(substr($strDate, 4, 2));
$intJour = intval(substr($strDate, 6, 2));
$intAnnee_Difference = (($strMode == 'A') ? $intDifference : 0);
$intMois_Difference = (($strMode == 'M') ? $intDifference : 0);
$intJour_Difference = (($strMode == 'J') ? $intDifference : 0);
if($intJour_Difference > 0) {
$intJour1 = $intJour + $intJour_Difference;
while($intJour1 > NZAU_RETOURNER_MOIS_TOTAL_JOURS($intMois, $intAnnee)) {
$intJour1 -= NZAU_RETOURNER_MOIS_TOTAL_JOURS($intMois, $intAnnee);
$intMois++;
if($intMois > 12) {
$intMois = 1;
$intAnnee++;
}
}
$intJour = $intJour1;
} elseif($intJour_Difference < 0) {
$intJour1 = $intJour - abs($intJour_Difference);
while($intJour1 < 1) {
$intMois--;
if($intMois < 1) {
$intMois = 12;
$intAnnee--;
}
$intJour1 += NZAU_RETOURNER_MOIS_TOTAL_JOURS($intMois, $intAnnee);
}
$intJour = $intJour1;
}
if($intMois_Difference > 0) {
$intMois1 = $intMois + $intMois_Difference;
$intAnnee += floor($intMois1 / 12);
$intMois = $intMois1 % 12;
if($intJour > NZAU_RETOURNER_MOIS_TOTAL_JOURS($intMois, $intAnnee)) {
$intJour = NZAU_RETOURNER_MOIS_TOTAL_JOURS($intMois, $intAnnee);
}
} elseif($intMois_Difference < 0) {
$intMois1 = $intMois - abs($intMois_Difference);
$intAnnee -= floor($intMois1 / 12);
$intMois = $intMois1 % 12;
if($intJour > NZAU_RETOURNER_MOIS_TOTAL_JOURS($intMois, $intAnnee)) {
$intJour = NZAU_RETOURNER_MOIS_TOTAL_JOURS($intMois, $intAnnee);
}
}
$intAnnee += $intAnnee_Difference;
return NZAU_RETOURNER_DATE($intJour, $intMois, $intAnnee);
}
function NZAU_RETOURNER_DATE_JJMMAAAA($strDate) {
$strAnnee = substr($strDate, 0, 4);
$strMois = substr($strDate, 4, 2);
$strJour = substr($strDate, 6, 2);
return sprintf('%s/%s/%s', $strJour, $strMois, $strAnnee);
}
function NZAU_RETOURNER_DATE($intJour, $intMois, $intAnnee) {
$intJour = abs(intval($intJour));
$intMois = abs(intval($intMois));
$intAnnee = abs(intval($intAnnee));
if($intJour == 0 || $intMois == 0 || $intAnnee == 0) {
return false;
} else {
$strJour = (($intJour < 10) ? '0' : '') . strval($intJour);
$strMois = (($intMois < 10) ? '0' : '') . strval($intMois);
$intAnnee += (($intAnnee < 100) ? 2000 : (($intAnnee < 1000) ? 1900 : 0));
$strAnnee = strval($intAnnee);
return sprintf('%s%s%s', $strAnnee, $strMois, $strJour);
}
}
?>