fix(imgsed): parsing of datetime string (#3738)

* refactor

* fix(imgsed): parsing of date

date_interval_create_from_date_string(): Unknown or bad format (an hour) at position 0 (a)
This commit is contained in:
Dag 2023-10-11 18:37:01 +02:00 committed by GitHub
parent 7e183915a9
commit d21f8cebf6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -43,15 +43,6 @@ class ImgsedBridge extends BridgeAbstract
'https://www.imgsed.com/instagram/' => ['context' => 'Username', 'u' => 'instagram', 'post' => 'on', 'story' => 'on', 'tagged' => 'on'],
];
public function getURI()
{
if (!is_null($this->getInput('u'))) {
return urljoin(self::URI, '/' . $this->getInput('u') . '/');
}
return parent::getURI();
}
public function collectData()
{
$username = $this->getInput('u');
@ -100,9 +91,6 @@ class ImgsedBridge extends BridgeAbstract
$isMoreContent = (bool) $post->find('svg', 0);
$moreContentNote = $isMoreContent ? '<p><i>(multiple images and/or videos)</i></p>' : '';
$this->items[] = [
'uri' => $url,
'author' => $author,
@ -214,15 +202,18 @@ HTML,
}
}
// Parse date, and transform the date into a timetamp, even in a case of a relative date
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';
}
$relativeDate = date_interval_create_from_date_string($dateString);
if ($relativeDate) {
@ -235,6 +226,15 @@ HTML,
return date_format($date, 'r');
}
public function getURI()
{
if (!is_null($this->getInput('u'))) {
return urljoin(self::URI, '/' . $this->getInput('u') . '/');
}
return parent::getURI();
}
private function convertURLToInstagram($url)
{
return str_replace(self::URI, self::INSTAGRAMURI, $url);