dl/includes/DelayCalculator.php
2020-06-17 20:49:28 +02:00

32 lines
841 B
PHP

<?php
class DelayCalculator {
private $currentTime;
public function __construct ($currentTime) {
if (!is_string($currentTime)) {
throw new InvalidArgumentException('$currentTime must be a string');
}
if (
( $this->currentTime = new DateTime($currentTime, $GLOBALS['timezone']) ) === false
) {
throw new InvalidArgumentException('$currentTime must be HH:MM');
}
#echo PHP_EOL;var_dump($this->currentTime);echo PHP_EOL;
}
public function calculateFromRemainingTime (DateInterval $timeToDeparture, DateTime $scheduledTime) {
$ct = clone $this->currentTime;
return $ct->add($timeToDeparture)->diff($scheduledTime);
}
public function calculateFromExpectedTime (DateTime $departureTime, DateTime $scheduledTime) {
return $departureTime->diff($scheduledTime);
}
}
?>