Skip to content

Commit

Permalink
[ImgsedBridge] More robust data parsing (#3766)
Browse files Browse the repository at this point in the history
Date Interval with the article "an" or "a" are now handled in a generic
way : every "article" is replaced by the number "1" instead of a
handling of multiple special case
  • Loading branch information
sysadminstory authored Oct 18, 2023
1 parent 563c2a3 commit 8203196
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions bridges/ImgsedBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,12 @@ private function parseDate($content)
{
// Parse date, and transform the date into a timetamp, even in a case of a relative date
$date = date_create();
$dateString = str_replace(' ago', '', $content);
// Special case : 'a day' is not a valid interval in PHP, so replace it with it's PHP equivalenbt : '1 day'
if ($dateString == 'a day') {
$dateString = '1 day';
}
if ($dateString === 'an hour') {
$dateString = '1 hour';
}

// Content trimmed to be sure that the "article" is at the beginning of the string and remove "ago" to make it a valid PHP date interval
$dateString = trim(str_replace(' ago', '', $content));

// Replace the article "an" or "a" by the number "1" to be a valid PHP date interval
$dateString = preg_replace('/^((an|a) )/m', '1 ', $dateString);

$relativeDate = date_interval_create_from_date_string($dateString);
if ($relativeDate) {
Expand Down

0 comments on commit 8203196

Please sign in to comment.