Skip to content

Commit e025878

Browse files
authored
Merge pull request #74 from NETWAYS/fix/missing-date
Fix missing item date and description
2 parents f02ae70 + 855d5b9 commit e025878

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

library/Feeds/Parser/Result/FeedItem.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ class FeedItem
1212
public ?Feed $feed = null;
1313
public ?string $title = null;
1414
public ?string $link = null;
15-
public ?string $description = null;
15+
public string $description = '';
1616
public array $categories = [];
1717
public ?string $creator = null;
1818
public ?string $image = null;
1919
public ?DateTime $date = null;
2020

2121
public function compareDate(FeedItem $other): int
2222
{
23-
$ad = $this->date ?? new DateTime('NOW');
24-
$bd = $other->date ?? new DateTime('NOW');
23+
$ad = $this->date ?? new DateTime('@0');
24+
$bd = $other->date ?? new DateTime('@0');
2525

2626
if ($ad == $bd) {
2727
return 0;

library/Feeds/Web/Item.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ protected function getCategoriesElement(): ?BaseHtmlElement
103103

104104
protected function getContentElement(): ?BaseHtmlElement
105105
{
106-
$text = $this->item->description;
106+
$text = $this->item->description ?? '';
107107
$description = new FeedContent($text);
108108

109109
return HtmlElement::create(
@@ -122,7 +122,10 @@ protected function getLink(): ?string
122122

123123
protected function getDate(): BaseHtmlElement
124124
{
125-
return (new TimeAgo($this->item->date->getTimestamp()));
125+
$d = $this->item->date;
126+
$ts = $this->item->date !== null ? $this->item->date->getTimestamp() : 0;
127+
128+
return (new TimeAgo($ts));
126129
}
127130

128131
protected function assembleHeader(): BaseHtmlElement

0 commit comments

Comments
 (0)