From 1b9b0b3644a59c324e095b046543aa57dbccb917 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sun, 30 Jan 2022 19:40:34 -0700 Subject: [PATCH] Fix UPS error when a tracking event doesn't have a date or time (wtf, UPS) --- lib/Tracking_UPS.lib.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Tracking_UPS.lib.php b/lib/Tracking_UPS.lib.php index 8af1e1b..b7180df 100644 --- a/lib/Tracking_UPS.lib.php +++ b/lib/Tracking_UPS.lib.php @@ -135,7 +135,6 @@ class Tracking_UPS { // $from->country = (string) $trackinfo->OriginCountryCode ?? ""; // // $info->setFrom($from); - // Only one entry, so put it in itself so the loop works if (!isset($trackinfo["Package"]["Activity"][0])) { $trackinfo["Package"]["Activity"] = [ @@ -148,10 +147,17 @@ class Tracking_UPS { $location->state = $history["ActivityLocation"]["Address"]["StateProvinceCode"] ?? ""; $location->zip = $history["ActivityLocation"]["Address"]["PostalCode"] ?? ""; $location->country = $history["ActivityLocation"]["Address"]["CountryCode"] ?? ""; + if (!empty($history["Date"]) && !empty($history["Time"])) { + $datetimestring = DateTime::createFromFormat('Ymd His', "$history[Date] $history[Time]")->format("c"); + } else if (!empty($history["Date"])) { + $datetimestring = DateTime::createFromFormat('Ymd His', "$history[Date]")->format("c"); + } else { + $datetimestring = ""; + } $info->appendHistoryEntry(new TrackingEntry( TrackingStatus::UPSEventTypeToStatus($history["Status"]["Type"]), $history["Status"]["Description"] ?? "Unknown", - DateTime::createFromFormat('Ymd His', "$history[Date] $history[Time]")->format("c"), + $datetimestring, $location )); }