In projects, update discussion URLs that have discussion too recent to have a full timestamp

This commit is contained in:
Alex Cabal 2025-01-29 18:46:00 -06:00
parent 4f4e72564a
commit d942f4642b

View file

@ -680,6 +680,21 @@ final class Project{
throw new Exception('Server responded with HTTP ' . $httpCode . '.');
}
// Posts that were today are listed as `n minutes ago` or `n hours ago`, without a timestamp. Try to approximate a timestamp if that's the case.
$matchCount = preg_match_all('/<span class="[^"]+?">[^<]+\(([\d]+ (?:minutes?|hours?) ago)\s*\)\s*<\/span>/ius', $response, $matches);
if($matchCount > 0){
// Unsure of the time zone, so just assume UTC.
try{
$this->LastDiscussionTimestamp = new DateTimeImmutable(str_replace('', ' ', $matches[1][sizeof($matches[1]) - 1]));
}
catch(\Exception $ex){
// Failed to parse date, pass.
$this->LastDiscussionTimestamp = null;
}
}
else{
// No `n minutes ago` matches, try to match a full timestamp.
$matchCount = preg_match_all('/<span class="[^"]+?">([a-z]{3} [\d]{1,2}, [\d]{4}, [\d]{1,2}:[\d]{1,2}:[\d]{1,2}(?:AM|PM))/iu', $response, $matches);
if($matchCount > 0){
@ -696,6 +711,7 @@ final class Project{
$this->LastDiscussionTimestamp = null;
}
}
}
catch(Exception $ex){
throw new Exceptions\AppException('Error when fetching discussion for URL <' . $this->DiscussionUrl . '>: ' . $ex->getMessage(), 0, $ex);
}