From 85ef5d75410d4f3c330f3b36ccf7d95216cb29f1 Mon Sep 17 00:00:00 2001 From: sysadminstory Date: Wed, 18 Oct 2023 00:26:44 +0200 Subject: [PATCH] [ImgsedBridge] More robust data parsing 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 --- bridges/ImgsedBridge.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/bridges/ImgsedBridge.php b/bridges/ImgsedBridge.php index e605cf4fbb2..12466c6b03b 100644 --- a/bridges/ImgsedBridge.php +++ b/bridges/ImgsedBridge.php @@ -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) {