feat: include optional time in transportation service
addresses #86996x46z
This commit is contained in:
@@ -43,6 +43,12 @@ class Service
|
||||
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
|
||||
public ?\DateTimeImmutable $dateFrom = null;
|
||||
|
||||
#[Groups(['api:single', 'api:list'])]
|
||||
public ?string $timeFrom = null;
|
||||
|
||||
#[Groups(['api:single', 'api:list'])]
|
||||
public ?string $dayTime = null;
|
||||
|
||||
#[Groups(['api:single', 'api:list'])]
|
||||
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
|
||||
public ?\DateTimeImmutable $dateTo = null;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\BusProNet\Utility;
|
||||
|
||||
class DayTimeUtility
|
||||
{
|
||||
public function mapTime(?string $time): ?string
|
||||
{
|
||||
if (null === $time) {
|
||||
return null;
|
||||
} elseif ($time >= '00:00' && $time <= '05:59') {
|
||||
return 'nachts';
|
||||
} elseif ($time >= '06:00' && $time <= '11:59') {
|
||||
return 'morgens';
|
||||
} elseif ($time >= '12:00' && $time <= '14:59') {
|
||||
return 'mittags';
|
||||
} elseif ($time >= '15:00' && $time <= '19:59') {
|
||||
return 'abends';
|
||||
} elseif ($time >= '20:00' && $time <= '23:59') {
|
||||
return 'nachts';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ use App\BusProNet\Model\Pickup;
|
||||
use App\BusProNet\Model\Room;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\BusProNet\Utility\DayTimeUtility;
|
||||
use App\BusProNet\Utility\TravelCodeUtility;
|
||||
use League\Flysystem\FilesystemOperator;
|
||||
use League\Flysystem\StorageAttributes;
|
||||
@@ -245,6 +246,11 @@ class TravelLoader extends AbstractLoader
|
||||
$service->direction = $this->getStringOrNullValue($serviceNode->filterXPath('//richtung'));
|
||||
$service->status = $this->getStringOrNullValue($serviceNode->filterXPath('//status'));
|
||||
|
||||
if (null !== $timeFrom = $serviceNode->attr('uhrzeit_von')) {
|
||||
$service->timeFrom = $timeFrom;
|
||||
$service->dayTime = (new DayTimeUtility())->mapTime($timeFrom);
|
||||
}
|
||||
|
||||
$transportationServices[$serviceId] = $service;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user