From 3203866e424b128545e5479b5d6c289b47d82e70 Mon Sep 17 00:00:00 2001 From: Kevin Arutyunyan Date: Wed, 22 Nov 2023 19:23:52 +0100 Subject: [PATCH] :children_crossing: Improve recognition of data as realtime (#2152) --- app/Http/Controllers/HafasController.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/HafasController.php b/app/Http/Controllers/HafasController.php index 9fe53bdde..25cb6a2bc 100644 --- a/app/Http/Controllers/HafasController.php +++ b/app/Http/Controllers/HafasController.php @@ -442,13 +442,15 @@ public static function fetchHafasTrip(string $tripID, string $lineName): HafasTr //remove "null" values $updatePayload = array_filter($updatePayload, 'strlen'); //TODO: This is deprecated, find a better way - if ($stopover->arrival !== null && Carbon::parse($stopover->arrival)->isFuture()) { + //the arrival and departure attributes are always included, so to recognize whether we have realtime data, + // arrivalDelay and departureDelay are checked for being null or not. + if ($stopover->arrival !== null && isset($stopover->arrivalDelay)) { $updatePayload['arrival_real'] = Carbon::parse($stopover->arrival); if ($stopover->arrivalPlatform !== null) { $updatePayload['arrival_platform_real'] = $stopover->arrivalPlatform; } } - if ($stopover->departure !== null && Carbon::parse($stopover->departure)->isFuture()) { + if ($stopover->departure !== null && isset($stopover->departureDelay)) { $updatePayload['departure_real'] = Carbon::parse($stopover->departure); if ($stopover->departurePlatform !== null) { $updatePayload['departure_platform_real'] = $stopover->departurePlatform; @@ -480,9 +482,7 @@ public static function fetchHafasTrip(string $tripID, string $lineName): HafasTr public static function refreshStopovers(stdClass $rawHafas): int { $payload = []; foreach ($rawHafas->stopovers ?? [] as $stopover) { - $timestampToCheck = Carbon::parse($stopover->departure ?? $stopover->arrival); - if ($timestampToCheck->isPast() || $timestampToCheck->isAfter(now()->addDay())) { - //HAFAS doesn't give as real time information on past stopovers, so... don't overwrite our data. :) + if (!isset($stopover->arrivalDelay) && !isset($stopover->departureDelay)) { continue; }