feat: sort pickups by date and time on import
This commit is contained in:
@@ -461,21 +461,27 @@ class DateImportService implements SingletonInterface, LoggerAwareInterface
|
||||
$timestamp = (string) $attributes['zeit'];
|
||||
$parts = explode(' ', $timestamp);
|
||||
if (2 === count($parts)) {
|
||||
[$datePart, $timePart] = $parts;
|
||||
[$pickupDate, $timePart] = $parts;
|
||||
$pickupTime = substr($timePart, 0, 5);
|
||||
} else {
|
||||
$datePart = null;
|
||||
[$timePart, ] = $parts;
|
||||
$pickupDate = $dateStart->format('d.m.Y');
|
||||
$pickupTime = $parts[0];
|
||||
}
|
||||
$pickupTime = sprintf('%s Uhr', substr($timePart, 0, 5));
|
||||
$pickupDate = $datePart;
|
||||
$pickups[] = [
|
||||
'bus_pro_id' => $busProId,
|
||||
'city' => $this->pickups[$busProId]['city'],
|
||||
'street' => $this->pickups[$busProId]['street'],
|
||||
'price' => (float) str_replace(',', '.', (string) $attributes['preis']),
|
||||
'time' => $pickupTime,
|
||||
'date' => $pickupDate,
|
||||
'time' => $pickupTime,
|
||||
];
|
||||
}
|
||||
usort($pickups, function ($a, $b) {
|
||||
$timeStampA = \DateTimeImmutable::createFromFormat('d.m.Y H:i', $a['date'].' '.$a['time']);
|
||||
$timeStampB = \DateTimeImmutable::createFromFormat('d.m.Y H:i', $b['date'].' '.$b['time']);
|
||||
|
||||
return $timeStampA <=> $timeStampB;
|
||||
});
|
||||
$date['pickups'] = serialize($pickups);
|
||||
|
||||
return $date;
|
||||
|
||||
Reference in New Issue
Block a user