Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class TimeTravel {
- private $start;
- private $end;
- public function __construct(DateTime $startDate, DateTime $endDate) {
- $this->startDate = $startDate;
- $this->endDate = $endDate;
- }
- public function getTravelInfo():string {
- $diff = $this->startDate->diff($this->endDate);
- return $diff->format('Il y a %y années, %m mois, %d jours, %h heures, %i minutes et %s secondes entre les deux dates');
- }
- public function findDate(int $interval):DateTime {
- $dateInterval = new DateInterval('PT' . $interval .'S' );
- return $this->startDate->sub($dateInterval);
- }
- public function backToFutureStepByStep($step):array {
- $result = [];
- $dateRange = new DatePeriod($this->startDate, $step, $this->endDate);
- foreach ($dateRange as $date) {
- $result[] = $date->format('M-d-y A-i:H:s');
- }
- return $result;
- }
- }
- $timeTrip = new TimeTravel(new DateTime('1985-12-31'), new DateTime());
- echo $timeTrip->getTravelInfo();
- $retour = $timeTrip->findDate(1000000000);
- echo "<br>". $retour->format("Y-m-d") . "<br>";
- $convecteur = $timeTrip->backToFutureStepByStep(new DateInterval('P1M1W1D'));
- var_dump($convecteur);
Add Comment
Please, Sign In to add comment