Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ImgsedBridge] More robust data parsing #3766

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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