Created
October 26, 2018 20:43
-
-
Save Karnak19/0114b21a7a100df604af4cd1567cb08d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| class TimeTravel { | |
| private $start; | |
| private $end; | |
| public function __construct($start, $end) { | |
| $this->start = $start; | |
| $this->end = $end; | |
| } | |
| public function getTravelInfo() { | |
| $interval = date_diff($this->start, $this->end); | |
| return 'Il y a'.$interval->format('%y').' années, '.$interval->format('%m').' mois, '.$interval->format('%d').' jours, '.$interval->format('%h') .' heures, '.$interval->format('%i').' minutes et '.$interval->format('%s').' secondes entre les deux dates\n'; | |
| } | |
| public function findDate($interval) { | |
| $dateToFind = new DateTime("1985-12-31"); | |
| $dateToFind->sub($interval); | |
| return 'Doc est bloqué le '.$dateToFind->format('d/m/y').'\n'; | |
| } | |
| public function backToFutureStepByStep(DatePeriod $period){ | |
| echo 'Etape à saisir dans le converteur temporel : \n'; | |
| foreach ($period as $date){ | |
| echo $date->format('M j Y A h:i').'\n'; | |
| } | |
| } | |
| } | |
| ?> |
This file contains hidden or 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 | |
| include 'TimeTravel.php'; | |
| $startDate = new DateTime('1998-07-12 12:13:40'); | |
| $endDate = new DateTime('2018-07-15 12:13:45'); | |
| $timeTravel = new timeTravel($startDate, $endDate); | |
| echo $timeTravel->getTravelInfo(); | |
| $temporalGap = new DateInterval('PT1000000000S'); | |
| echo $timeTravel->findDate($temporalGap); | |
| $start = new DateTime('2010-07-01'); | |
| $step = new DateInterval('P1M1W1D'); | |
| $end = new DateTime(); | |
| $period = new DatePeriod($start, $step, $end); | |
| $timeTravel->backToFutureStepByStep($period); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment