Updated scheduled tasks

This commit is contained in:
2026-07-03 12:18:00 +10:00
parent 30d5feaf63
commit 85c587cb1e
@@ -144,8 +144,8 @@ class GetAircraftInfoForArrivedFlights extends Command
$data->aircraft_registration,
$updates['aircraft_registration'] ?? null,
),
$this->describeDate('Departure', $originalDeparture, $data->estimated_departure_utc, $updates['departure_date'] ?? null),
$this->describeDate('Arrival', $originalArrival, $data->estimated_arrival_utc, $updates['arrival_date'] ?? null),
$this->describeDate('Departure', $originalDeparture, $data->estimated_departure_utc, $updates['departure_date'] ?? null, $flight->departureAirport->timezone),
$this->describeDate('Arrival', $originalArrival, $data->estimated_arrival_utc, $updates['arrival_date'] ?? null, $flight->arrivalAirport->timezone),
$this->describeAircraftType($originalAircraft, $newAircraft, $data->equipment_iata, $aircraftNotFound),
];
@@ -179,23 +179,37 @@ class GetAircraftInfoForArrivedFlights extends Command
return "{$label}: {$fromLabel}{$apiValue}";
}
protected function describeDate(string $label, ?CarbonInterface $from, ?CarbonInterface $apiValue, mixed $applied): string
protected function describeDate(string $label, ?CarbonInterface $from, ?CarbonInterface $apiValue, mixed $applied, string $timezone): string
{
$fromLabel = $from?->format('j M Y H:i') . ' ' . ($from?->tzName ?? '') ?: 'Unknown';
$toLocal = $apiValue?->copy()->setTimezone($timezone);
$fromLocal = $from?->copy()->setTimezone($timezone);
if (!$apiValue) {
if (!$toLocal) {
$fromLabel = $fromLocal ? $this->formatFlightTime($fromLocal) : 'Unknown';
return "{$label}: {$fromLabel} (not returned by API — no change)";
}
$toLabel = $apiValue->format('j M Y H:i') . ' ' . $apiValue->tzName;
if (!$applied) {
return "{$label}: {$toLabel} (no change)";
return "{$label}: " . $this->formatFlightTime($toLocal) . " (no change)";
}
// Only bother showing the date if it actually changed (e.g. delayed past midnight).
$showDate = !$fromLocal || !$fromLocal->isSameDay($toLocal);
$showYear = $showDate && $fromLocal && $fromLocal->year !== $toLocal->year;
$fromLabel = $fromLocal ? $this->formatFlightTime($fromLocal, $showDate, $showYear) : 'Unknown';
$toLabel = $this->formatFlightTime($toLocal, $showDate, $showYear);
return "{$label}: {$fromLabel}{$toLabel}";
}
protected function formatFlightTime(CarbonInterface $time, bool $showDate = false, bool $showYear = false): string
{
$datePart = $showDate ? $time->format($showYear ? 'j M Y, ' : 'j M, ') : '';
return $datePart . $time->format('g:ia') . ' ' . $time->format('T');
}
protected function describeAircraftType(?Aircraft $from, ?Aircraft $to, ?string $equipmentIata, bool $notFound): string
{
$fromLabel = $from?->display_name_short ?? 'None';