43 lines
1 KiB
PHP
43 lines
1 KiB
PHP
<?php
|
|
|
|
class DepartureFormatter {
|
|
|
|
//$realdeparturecalendar, $scheduleddeparture,
|
|
public static function format ($realdeparture, DelayCalculator $delayc) {
|
|
|
|
//$scheduleddepartureObj = new DateTime('@'.($scheduleddeparture/1000), $GLOBALS['timezone']);
|
|
|
|
//$delay = $realdepartureObj->diff($scheduleddepartureObj);
|
|
|
|
|
|
$realtime = null;
|
|
|
|
// Not realtime
|
|
if ( preg_match('/([12]?\d):([0-5]\d)/', $realdeparture) === 1 ) {
|
|
$realtime = false;
|
|
$time = DateTime::createFromFormat("G:i", $realdeparture, $GLOBALS['timezone']);
|
|
}
|
|
// Realtime
|
|
else {
|
|
$matches = array();
|
|
if ( preg_match('/(\d+)\'/', $realdeparture, $matches) === 1 ) {
|
|
$realtime = true;
|
|
$time = new DateTime("now", $GLOBALS['timezone']);
|
|
$time->add(new DateInterval("PT".$matches[1]."M"));
|
|
}
|
|
}
|
|
|
|
//$scheduleddepartureObj->setTimezone($GLOBALS['timezone']);
|
|
return array(
|
|
//$scheduleddepartureObj->format('G:i'),
|
|
$time->format('G:i'),
|
|
"+0",
|
|
//$delay->format('%R%i'),
|
|
$realtime
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|