Skip to content

Commit

Permalink
fix: do not fail on invalid time strings
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz committed Jan 5, 2025
1 parent 59446ed commit f608cb3
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/Fetcher/FeedFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ public function fetch(
$url2->setUserinfo(rawurlencode($user), rawurlencode($password));
}
if (!is_null($httpLastModified) && trim($httpLastModified) !== '') {
$lastModified = new DateTime($httpLastModified);
try {
$lastModified = new DateTime($httpLastModified);
} catch (\Exception) {
$lastModified = null;
}
} else {
$lastModified = null;
}
Expand Down Expand Up @@ -294,11 +298,15 @@ protected function buildItem(
$item->setGuidHash(md5($item->getGuid()));

$lastModified = $parsedItem->getLastModified() ?? new DateTime();
if ($parsedItem->getValue('pubDate') !== null) {
$pubDT = new DateTime($parsedItem->getValue('pubDate'));
} elseif ($parsedItem->getValue('published') !== null) {
$pubDT = new DateTime($parsedItem->getValue('published'));
} else {
try {
if ($parsedItem->getValue('pubDate') !== null) {
$pubDT = new DateTime($parsedItem->getValue('pubDate'));
} elseif ($parsedItem->getValue('published') !== null) {
$pubDT = new DateTime($parsedItem->getValue('published'));
} else {
$pubDT = $lastModified;
}
} catch (\Exception) {
$pubDT = $lastModified;
}

Expand Down

0 comments on commit f608cb3

Please sign in to comment.