32 lines
No EOL
841 B
PHP
32 lines
No EOL
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);
|
|
}
|
|
|
|
}
|
|
|
|
?>
|