Workaround undocumented USPS API bullshit again

master
Skylar Ittner 2 years ago
parent b43e8b8d37
commit 10c166f035

@ -178,6 +178,7 @@ class TrackingStatus {
case "CI": // stuck in customs
case "AT": // departed a transfer airport (int'l)
case "A0": // "Acceptance" from foreign country
case "CO": // "Inbound Out of Customs"
return TrackingStatus::TRACKING_STATUS_TRANSIT;
case "01":
case "13":

@ -89,16 +89,28 @@ class Tracking_USPS {
$info->setTo($to);
foreach ($trackinfo->TrackDetail as $history) {
for ($i = 0; $i < count($trackinfo->TrackDetail); $i++) {
$history = $trackinfo->TrackDetail[$i];
$location = new Location();
$location->city = (string) $history->EventCity ?? "";
$location->state = (string) $history->EventState ?? "";
$location->zip = (string) $history->EventZIPCode ?? "";
$location->country = (string) $history->EventCountry ?? "";
if ((empty($history->EventDate) || empty($history->EventTime)) && $i < count($trackinfo->TrackDetail) - 1) {
// If there's no date/time for some reason (yes this happens sometimes apparently),
// just make it 60 seconds after the previous event.
// This way it'll be in the correct order if the events are displayed
// after being sorted by date/time.
// Because events are ordered latest first, we get $i+1 to get the previous event.
$datetime = date("Y-m-d H:i:s", strtotime($trackinfo->TrackDetail[$i + 1]->EventDate . " " . $trackinfo->TrackDetail[$i + 1]->EventTime) + 60);
} else {
$datetime = $history->EventDate . " " . $history->EventTime;
}
$info->appendHistoryEntry(new TrackingEntry(
TrackingStatus::USPSEventCodeToStatus((string) $history->EventCode),
((string) $history->Event),
$history->EventDate . " " . $history->EventTime,
$datetime,
$location,
TrackingStatus::isUSPSEventCodeContainerScan((string) $history->EventCode)));
}

Loading…
Cancel
Save