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'];
|
$timestamp = (string) $attributes['zeit'];
|
||||||
$parts = explode(' ', $timestamp);
|
$parts = explode(' ', $timestamp);
|
||||||
if (2 === count($parts)) {
|
if (2 === count($parts)) {
|
||||||
[$datePart, $timePart] = $parts;
|
[$pickupDate, $timePart] = $parts;
|
||||||
|
$pickupTime = substr($timePart, 0, 5);
|
||||||
} else {
|
} else {
|
||||||
$datePart = null;
|
$pickupDate = $dateStart->format('d.m.Y');
|
||||||
[$timePart, ] = $parts;
|
$pickupTime = $parts[0];
|
||||||
}
|
}
|
||||||
$pickupTime = sprintf('%s Uhr', substr($timePart, 0, 5));
|
|
||||||
$pickupDate = $datePart;
|
|
||||||
$pickups[] = [
|
$pickups[] = [
|
||||||
|
'bus_pro_id' => $busProId,
|
||||||
'city' => $this->pickups[$busProId]['city'],
|
'city' => $this->pickups[$busProId]['city'],
|
||||||
'street' => $this->pickups[$busProId]['street'],
|
'street' => $this->pickups[$busProId]['street'],
|
||||||
'price' => (float) str_replace(',', '.', (string) $attributes['preis']),
|
'price' => (float) str_replace(',', '.', (string) $attributes['preis']),
|
||||||
'time' => $pickupTime,
|
|
||||||
'date' => $pickupDate,
|
'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);
|
$date['pickups'] = serialize($pickups);
|
||||||
|
|
||||||
return $date;
|
return $date;
|
||||||
|
|||||||
Reference in New Issue
Block a user