Created
June 23, 2016 13:37
-
-
Save cotcotquedec/53f970ea532533e248a66bc50c3e7e01 to your computer and use it in GitHub Desktop.
Test recrutement php lvl1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$the_date = date('Y-m-d', rand(0, time())); | |
?> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
<meta http-equiv="EXPIRES" content="0" /> | |
<meta http-equiv="Pragma" content="no-cache" /> | |
<title>Petit test : Bissextile!</title> | |
</head> | |
<body> | |
<h2>Objectif : </h2> | |
<div class="rules">- Indiquer la prochaine année où elle tombe le même jour de la semaine!</div> | |
<h2>Réalisation : </h2> | |
<div id="todo"></div> | |
</body> | |
</html> |
$theDate = date('Y-m-d', rand(0, time()));
$dateObject = DateTime::createFromFormat('Y-m-d', $theDate);
$referenceDay = $dateObject->format("w");
while (1) {
$dateObject->modify('+1 year');
if ($dateObject->format("L") && $dateObject->format("w") == $referenceDay) {
echo 'From ' . $theDate . ' the next occurence is ' . $dateObject->format("Y");
exit();
}
}
$today = new \DateTime();
$dayofWeek = $today->format('w');
$date = clone $today;
$interval = new \DateInterval('P1Y');
do {
$date->add($interval);
if ($date->format('w') == $dayofWeek) {
echo "La réponse est " . $date->format('Y') . " (" . $date->format('D. d/m/Y') . ")";
break;
}
}
while (true);
Je n'avais pas vu qu'il y a avait des réponses. Ben je vais continuer a faire des tests!!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cadeau: