当前位置: 首页>>代码示例>>PHP>>正文


PHP tools::transformDuration方法代码示例

本文整理汇总了PHP中tools::transformDuration方法的典型用法代码示例。如果您正苦于以下问题:PHP tools::transformDuration方法的具体用法?PHP tools::transformDuration怎么用?PHP tools::transformDuration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tools的用法示例。


在下文中一共展示了tools::transformDuration方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: parseHafasXml

 public static function parseHafasXml($serverData, $lang, $fast, $showAlerts = false)
 {
     $xml = new SimpleXMLElement($serverData);
     $connection = [];
     $i = 0;
     if (isset($xml->ConRes->ConnectionList->Connection)) {
         $fromstation = self::getStationFromHafasDescription($xml->ConRes->ConnectionList->Connection[0]->Overview->Departure->BasicStop->Station['name'], $xml->ConRes->ConnectionList->Connection[0]->Overview->Departure->BasicStop->Station['x'], $xml->ConRes->ConnectionList->Connection[0]->Overview->Departure->BasicStop->Station['y'], $lang);
         $tostation = self::getStationFromHafasDescription($xml->ConRes->ConnectionList->Connection[0]->Overview->Arrival->BasicStop->Station['name'], $xml->ConRes->ConnectionList->Connection[0]->Overview->Arrival->BasicStop->Station['x'], $xml->ConRes->ConnectionList->Connection[0]->Overview->Arrival->BasicStop->Station['y'], $lang);
         foreach ($xml->ConRes->ConnectionList->Connection as $conn) {
             $connection[$i] = new Connection();
             $connection[$i]->duration = tools::transformDuration($conn->Overview->Duration->Time);
             $connection[$i]->departure = new DepartureArrival();
             $connection[$i]->departure->station = $fromstation;
             $connection[$i]->departure->direction = trim($conn->Overview->Departure->BasicStop->Dep->Platform->Text);
             $connection[$i]->departure->time = tools::transformTime($conn->Overview->Departure->BasicStop->Dep->Time, $conn->Overview->Date);
             $connection[$i]->departure->canceled = $conn->Overview->Departure->BasicStop->StopPrognosis->Status != "SCHEDULED" ? true : false;
             $connection[$i]->arrival = new DepartureArrival();
             $connection[$i]->arrival->station = $tostation;
             $connection[$i]->arrival->time = tools::transformTime($conn->Overview->Arrival->BasicStop->Arr->Time, $conn->Overview->Date);
             $connection[$i]->arrival->canceled = $conn->Overview->Arrival->BasicStop->StopPrognosis->Status != "SCHEDULED" ? true : false;
             //Delay and platform changes
             $departureDelay = 0;
             $departurePlatform = trim($conn->Overview->Departure->BasicStop->Dep->Platform->Text);
             $departurePlatformNormal = true;
             $arrivalDelay = 0;
             $arrivalPlatform = trim($conn->Overview->Arrival->BasicStop->Arr->Platform->Text);
             $arrivalPlatformNormal = true;
             if ($conn->RtStateList->RtState['value'] == 'HAS_DELAYINFO') {
                 //echo "delay: " .$conn->Overview -> Departure -> BasicStop -> StopPrognosis -> Dep -> Time . "\n";
                 $departureDelay = tools::transformTime($conn->Overview->Departure->BasicStop->StopPrognosis->Dep->Time, $conn->Overview->Date) - $connection[$i]->departure->time;
                 if ($departureDelay < 0) {
                     $departureDelay = 0;
                 }
                 $arrivalDelay = tools::transformTime($conn->Overview->Arrival->BasicStop->StopPrognosis->Arr->Time, $conn->Overview->Date) - $connection[$i]->arrival->time;
                 if ($arrivalDelay < 0) {
                     $arrivalDelay = 0;
                 }
                 if (isset($conn->Overview->Departure->BasicStop->StopPrognosis->Dep->Platform->Text)) {
                     $departurePlatform = trim($conn->Overview->Departure->BasicStop->StopPrognosis->Dep->Platform->Text);
                     $departurePlatformNormal = false;
                 }
                 if (isset($conn->Overview->Arrival->BasicStop->StopPrognosis->Arr->Platform->Text)) {
                     $arrivalPlatform = trim($conn->Overview->Arrival->BasicStop->StopPrognosis->Arr->Platform->Text);
                     $arrivalPlatformNormal = false;
                 }
             }
             // Alerts
             if ($showAlerts && isset($conn->IList)) {
                 $alerts = [];
                 foreach ($conn->IList->I as $info) {
                     $alert = new Alert();
                     $alert->header = htmlentities(trim($info['header']));
                     $alert->description = htmlentities(trim($info['text']));
                     array_push($alerts, $alert);
                 }
                 $connection[$i]->alert = $alerts;
             }
             $connection[$i]->departure->delay = $departureDelay;
             $connection[$i]->departure->platform = new Platform();
             $connection[$i]->departure->platform->name = $departurePlatform;
             $connection[$i]->departure->platform->normal = $departurePlatformNormal;
             $connection[$i]->arrival->delay = $arrivalDelay;
             $connection[$i]->arrival->platform = new Platform();
             $connection[$i]->arrival->platform->name = $arrivalPlatform;
             $connection[$i]->arrival->platform->normal = $arrivalPlatformNormal;
             $trains = [];
             $vias = [];
             $directions = [];
             $j = 0;
             $k = 0;
             $connectionindex = 0;
             if (isset($conn->ConSectionList->ConSection)) {
                 foreach ($conn->ConSectionList->ConSection as $connsection) {
                     if (isset($connsection->Journey->JourneyAttributeList->JourneyAttribute)) {
                         foreach ($connsection->Journey->JourneyAttributeList->JourneyAttribute as $att) {
                             if ($att->Attribute['type'] == 'NAME') {
                                 $trains[$j] = str_replace(' ', '', $att->Attribute->AttributeVariant->Text);
                                 $j++;
                             } elseif ($att->Attribute['type'] == 'DIRECTION') {
                                 $__stat = new stdClass();
                                 //This recently changed: only fetch direction name, nothing else.
                                 $__stat->name = str_replace(' [NMBS/SNCB]', '', trim($att->Attribute->AttributeVariant->Text));
                                 $directions[$k] = $__stat;
                                 $k++;
                             }
                         }
                         if ($conn->Overview->Transfers > 0 && strcmp($connsection->Arrival->BasicStop->Station['name'], $conn->Overview->Arrival->BasicStop->Station['name']) != 0) {
                             //current index for the train: j-1
                             $connarray = $conn->ConSectionList->ConSection;
                             $departTime = tools::transformTime($connarray[$connectionindex + 1]->Departure->BasicStop->Dep->Time, $conn->Overview->Date);
                             $departPlatform = trim($connarray[$connectionindex + 1]->Departure->BasicStop->Dep->Platform->Text);
                             $departDelay = 0;
                             //Todo: NYImplemented
                             $departcanceled = $connarray[$connectionindex + 1]->Departure->BasicStop->StopPrognosis->Status != "SCHEDULED" ? true : false;
                             $arrivalTime = tools::transformTime($connsection->Arrival->BasicStop->Arr->Time, $conn->Overview->Date);
                             $arrivalPlatform = trim($connsection->Arrival->BasicStop->Arr->Platform->Text);
                             $arrivalDelay = 0;
                             //Todo: NYImplemented
                             $arrivalcanceled = $connarray[$connectionindex + 1]->Arrival->BasicStop->StopPrognosis->Status != "SCHEDULED" ? true : false;
                             $vias[$connectionindex] = new Via();
//.........这里部分代码省略.........
开发者ID:jncn,项目名称:iRail,代码行数:101,代码来源:connections.php

示例2: parseHafasXml

 public static function parseHafasXml($serverData, $lang)
 {
     $xml = new SimpleXMLElement($serverData);
     $connection = array();
     $i = 0;
     //DEBUG: echo $serverData ;
     if (isset($xml->ConRes->ConnectionList->Connection)) {
         //get stations from & to once for all connections
         $fromstation = connections::getStationFromHafasLocation($xml->ConRes->ConnectionList->Connection[0]->Overview->Departure->BasicStop->Station['x'], $xml->ConRes->ConnectionList->Connection[0]->Overview->Departure->BasicStop->Station['y'], $lang);
         $tostation = connections::getStationFromHafasLocation($xml->ConRes->ConnectionList->Connection[0]->Overview->Arrival->BasicStop->Station['x'], $xml->ConRes->ConnectionList->Connection[0]->Overview->Arrival->BasicStop->Station['y'], $lang);
         foreach ($xml->ConRes->ConnectionList->Connection as $conn) {
             $connection[$i] = new Connection();
             $connection[$i]->departure = new DepartureArrival();
             $connection[$i]->arrival = new DepartureArrival();
             $connection[$i]->duration = tools::transformDuration($conn->Overview->Duration->Time);
             $connection[$i]->departure->station = $fromstation;
             $connection[$i]->departure->time = tools::transformTime($conn->Overview->Departure->BasicStop->Dep->Time, $conn->Overview->Date);
             $connection[$i]->departure->platform = new Platform();
             $connection[$i]->departure->direction = trim($conn->Overview->Departure->BasicStop->Dep->Platform->Text);
             $connection[$i]->departure->platform->name = trim($conn->Overview->Departure->BasicStop->Dep->Platform->Text);
             $connection[$i]->arrival->time = tools::transformTime($conn->Overview->Arrival->BasicStop->Arr->Time, $conn->Overview->Date);
             $connection[$i]->arrival->platform = new Platform();
             $connection[$i]->arrival->platform->name = trim($conn->Overview->Arrival->BasicStop->Arr->Platform->Text);
             $connection[$i]->arrival->station = $tostation;
             //Delay and platform changes //TODO: get Delay from railtime instead - much better information
             $delay0 = 0;
             $delay1 = 0;
             $platformNormal0 = true;
             $platformNormal1 = true;
             if ($conn->RtStateList->RtState["value"] == "HAS_DELAYINFO") {
                 $delay0 = tools::transformTime($conn->Overview->Departure->BasicStop->StopPrognosis->Dep->Time, $conn->Overview->Date) - $connection[$i]->departure->time;
                 if ($delay0 < 0) {
                     $delay0 = 0;
                 }
                 //echo "delay: " .$conn->Overview -> Departure -> BasicStop -> StopPrognosis -> Dep -> Time . "\n";
                 $delay1 = tools::transformTime($conn->Overview->Arrival->BasicStop->StopPrognosis->Arr->Time, $conn->Overview->Date) - $connection[$i]->arrival->time;
                 if ($delay1 < 0) {
                     $delay1 = 0;
                 }
                 if (isset($conn->Overview->Departure->BasicStop->StopPrognosis->Dep->Platform->Text)) {
                     $platform0 = trim($conn->Overview->Departure->BasicStop->StopPrognosis->Dep->Platform->Text);
                     $platformNormal0 = false;
                 }
                 if (isset($conn->Overview->Arrival->BasicStop->StopPrognosis->Arr->Platform->Text)) {
                     $platform1 = trim($conn->Overview->Arrival->BasicStop->StopPrognosis->Arr->Platform->Text);
                     $platformNormal1 = false;
                 }
             }
             $connection[$i]->departure->delay = $delay0;
             $connection[$i]->departure->platform->normal = $platformNormal0;
             $connection[$i]->arrival->delay = $delay1;
             $connection[$i]->arrival->platform->normal = $platformNormal1;
             $trains = array();
             $vias = array();
             $directions = array();
             $j = 0;
             $k = 0;
             $connectionindex = 0;
             //yay for spaghetti code.
             if (isset($conn->ConSectionList->ConSection)) {
                 foreach ($conn->ConSectionList->ConSection as $connsection) {
                     if (isset($connsection->Journey->JourneyAttributeList->JourneyAttribute)) {
                         foreach ($connsection->Journey->JourneyAttributeList->JourneyAttribute as $att) {
                             if ($att->Attribute["type"] == "NAME") {
                                 $trains[$j] = str_replace(" ", "", $att->Attribute->AttributeVariant->Text);
                                 $j++;
                             } else {
                                 if ($att->Attribute["type"] == "DIRECTION") {
                                     $directions[$k] = stations::getStationFromName(trim($att->Attribute->AttributeVariant->Text), $lang);
                                     $k++;
                                 }
                             }
                         }
                         if ($conn->Overview->Transfers > 0 && strcmp($connsection->Arrival->BasicStop->Station['name'], $conn->Overview->Arrival->BasicStop->Station['name']) != 0) {
                             //current index for the train: j-1
                             $departDelay = 0;
                             //Todo: NYImplemented
                             $connarray = $conn->ConSectionList->ConSection;
                             $departTime = tools::transformTime($connarray[$connectionindex + 1]->Departure->BasicStop->Dep->Time, $conn->Overview->Date);
                             $departPlatform = trim($connarray[$connectionindex + 1]->Departure->BasicStop->Dep->Platform->Text);
                             $arrivalTime = tools::transformTime($connsection->Arrival->BasicStop->Arr->Time, $conn->Overview->Date);
                             $arrivalPlatform = trim($connsection->Arrival->BasicStop->Arr->Platform->Text);
                             $arrivalDelay = 0;
                             //Todo: NYImplemented
                             $vias[$connectionindex] = new Via();
                             $vias[$connectionindex]->arrival = new ViaDepartureArrival();
                             $vias[$connectionindex]->arrival->time = $arrivalTime;
                             $vias[$connectionindex]->arrival->platform = new Platform();
                             $vias[$connectionindex]->arrival->platform->name = $arrivalPlatform;
                             $vias[$connectionindex]->arrival->platform->normal = 1;
                             $vias[$connectionindex]->departure = new ViaDepartureArrival();
                             $vias[$connectionindex]->departure->time = $departTime;
                             $vias[$connectionindex]->departure->platform = new Platform();
                             $vias[$connectionindex]->departure->platform->name = $departPlatform;
                             $vias[$connectionindex]->departure->platform->normal = 1;
                             $vias[$connectionindex]->timeBetween = $departTime - $arrivalTime;
                             $vias[$connectionindex]->direction = $directions[$k - 1];
                             $vias[$connectionindex]->vehicle = "BE.NMBS." . $trains[$j - 1];
                             $vias[$connectionindex]->station = connections::getStationFromHafasLocation($connsection->Arrival->BasicStop->Station['x'], $connsection->Arrival->BasicStop->Station['y'], $lang);
                             $connectionindex++;
//.........这里部分代码省略.........
开发者ID:JeroenDeDauw,项目名称:iRail,代码行数:101,代码来源:connections.php

示例3: parseHafasXml

 public static function parseHafasXml($serverData, $lang, $fast)
 {
     $xml = new SimpleXMLElement($serverData);
     $connection = [];
     $i = 0;
     //DEBUG:
     //echo $serverData ;
     if (isset($xml->ConRes->ConnectionList->Connection)) {
         //get stations from & to once for all connections
         $fromstation = connections::getStationFromHafasDescription($xml->ConRes->ConnectionList->Connection[0]->Overview->Departure->BasicStop->Station['name'], $xml->ConRes->ConnectionList->Connection[0]->Overview->Departure->BasicStop->Station['x'], $xml->ConRes->ConnectionList->Connection[0]->Overview->Departure->BasicStop->Station['y'], $lang);
         $tostation = connections::getStationFromHafasDescription($xml->ConRes->ConnectionList->Connection[0]->Overview->Arrival->BasicStop->Station['name'], $xml->ConRes->ConnectionList->Connection[0]->Overview->Arrival->BasicStop->Station['x'], $xml->ConRes->ConnectionList->Connection[0]->Overview->Arrival->BasicStop->Station['y'], $lang);
         foreach ($xml->ConRes->ConnectionList->Connection as $conn) {
             $connection[$i] = new Connection();
             $connection[$i]->departure = new DepartureArrival();
             $connection[$i]->arrival = new DepartureArrival();
             $connection[$i]->duration = tools::transformDuration($conn->Overview->Duration->Time);
             $connection[$i]->departure->station = $fromstation;
             $connection[$i]->departure->time = tools::transformTime($conn->Overview->Departure->BasicStop->Dep->Time, $conn->Overview->Date);
             $connection[$i]->departure->platform = new Platform();
             $connection[$i]->departure->direction = trim($conn->Overview->Departure->BasicStop->Dep->Platform->Text);
             $connection[$i]->departure->platform->name = trim($conn->Overview->Departure->BasicStop->Dep->Platform->Text);
             $connection[$i]->arrival->time = tools::transformTime($conn->Overview->Arrival->BasicStop->Arr->Time, $conn->Overview->Date);
             $connection[$i]->arrival->platform = new Platform();
             $connection[$i]->arrival->platform->name = trim($conn->Overview->Arrival->BasicStop->Arr->Platform->Text);
             $connection[$i]->arrival->station = $tostation;
             //Delay and platform changes //TODO: get Delay from railtime instead - much better information
             $delay0 = 0;
             $delay1 = 0;
             $platformNormal0 = true;
             $platformNormal1 = true;
             if ($conn->RtStateList->RtState["value"] == "HAS_DELAYINFO") {
                 $delay0 = tools::transformTime($conn->Overview->Departure->BasicStop->StopPrognosis->Dep->Time, $conn->Overview->Date) - $connection[$i]->departure->time;
                 if ($delay0 < 0) {
                     $delay0 = 0;
                 }
                 //echo "delay: " .$conn->Overview -> Departure -> BasicStop -> StopPrognosis -> Dep -> Time . "\n";
                 $delay1 = tools::transformTime($conn->Overview->Arrival->BasicStop->StopPrognosis->Arr->Time, $conn->Overview->Date) - $connection[$i]->arrival->time;
                 if ($delay1 < 0) {
                     $delay1 = 0;
                 }
                 if (isset($conn->Overview->Departure->BasicStop->StopPrognosis->Dep->Platform->Text)) {
                     $platform0 = trim($conn->Overview->Departure->BasicStop->StopPrognosis->Dep->Platform->Text);
                     $platformNormal0 = false;
                 }
                 if (isset($conn->Overview->Arrival->BasicStop->StopPrognosis->Arr->Platform->Text)) {
                     $platform1 = trim($conn->Overview->Arrival->BasicStop->StopPrognosis->Arr->Platform->Text);
                     $platformNormal1 = false;
                 }
             }
             $connection[$i]->departure->delay = $delay0;
             $connection[$i]->departure->platform->normal = $platformNormal0;
             $connection[$i]->arrival->delay = $delay1;
             $connection[$i]->arrival->platform->normal = $platformNormal1;
             $trains = [];
             $vias = [];
             $directions = [];
             $j = 0;
             $k = 0;
             $connectionindex = 0;
             //yay for spaghetti code.
             if (isset($conn->ConSectionList->ConSection)) {
                 foreach ($conn->ConSectionList->ConSection as $connsection) {
                     if (isset($connsection->Journey->JourneyAttributeList->JourneyAttribute)) {
                         foreach ($connsection->Journey->JourneyAttributeList->JourneyAttribute as $att) {
                             if ($att->Attribute["type"] == "NAME") {
                                 $trains[$j] = str_replace(" ", "", $att->Attribute->AttributeVariant->Text);
                                 $j++;
                             } elseif ($att->Attribute["type"] == "DIRECTION") {
                                 $__stat = new stdClass();
                                 //This recently changed: only fetch direction name, nothing else.
                                 $__stat->name = str_replace(" [NMBS/SNCB]", "", trim($att->Attribute->AttributeVariant->Text));
                                 $directions[$k] = $__stat;
                                 $k++;
                             }
                         }
                         if ($conn->Overview->Transfers > 0 && strcmp($connsection->Arrival->BasicStop->Station['name'], $conn->Overview->Arrival->BasicStop->Station['name']) != 0) {
                             //current index for the train: j-1
                             $departDelay = 0;
                             //Todo: NYImplemented
                             $connarray = $conn->ConSectionList->ConSection;
                             $departTime = tools::transformTime($connarray[$connectionindex + 1]->Departure->BasicStop->Dep->Time, $conn->Overview->Date);
                             $departPlatform = trim($connarray[$connectionindex + 1]->Departure->BasicStop->Dep->Platform->Text);
                             $arrivalTime = tools::transformTime($connsection->Arrival->BasicStop->Arr->Time, $conn->Overview->Date);
                             $arrivalPlatform = trim($connsection->Arrival->BasicStop->Arr->Platform->Text);
                             $arrivalDelay = 0;
                             //Todo: NYImplemented
                             $vias[$connectionindex] = new Via();
                             $vias[$connectionindex]->arrival = new ViaDepartureArrival();
                             $vias[$connectionindex]->arrival->time = $arrivalTime;
                             $vias[$connectionindex]->arrival->platform = new Platform();
                             $vias[$connectionindex]->arrival->platform->name = $arrivalPlatform;
                             $vias[$connectionindex]->arrival->platform->normal = 1;
                             $vias[$connectionindex]->departure = new ViaDepartureArrival();
                             $vias[$connectionindex]->departure->time = $departTime;
                             $vias[$connectionindex]->departure->platform = new Platform();
                             $vias[$connectionindex]->departure->platform->name = $departPlatform;
                             $vias[$connectionindex]->departure->platform->normal = 1;
                             $vias[$connectionindex]->timeBetween = $departTime - $arrivalTime;
                             if (isset($directions[$k - 1])) {
                                 $vias[$connectionindex]->direction = $directions[$k - 1];
//.........这里部分代码省略.........
开发者ID:Tjoosten,项目名称:iRail,代码行数:101,代码来源:connections.php


注:本文中的tools::transformDuration方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。