Skip to content

Commit

Permalink
🚸 Improve recognition of data as realtime (#2152)
Browse files Browse the repository at this point in the history
  • Loading branch information
d3d9 authored Nov 22, 2023
1 parent 68d5763 commit 3203866
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/Http/Controllers/HafasController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 3203866

Please sign in to comment.