diff --git a/lib/TrackingStatus.lib.php b/lib/TrackingStatus.lib.php index fef62bb..8c6be53 100644 --- a/lib/TrackingStatus.lib.php +++ b/lib/TrackingStatus.lib.php @@ -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": diff --git a/lib/Tracking_USPS.lib.php b/lib/Tracking_USPS.lib.php index 87aafa2..8f79aac 100644 --- a/lib/Tracking_USPS.lib.php +++ b/lib/Tracking_USPS.lib.php @@ -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))); }